Hacker News new | ask | show | jobs
by tomlu 4856 days ago
It seems like this problem would be elegantly solved by starting a thread, green thread or coroutine (depending on language) for each task and calling the API functions synchronously from within that. I'm not sure what support JS has for these things.
3 comments

Precisely. Threads allow you to separate concerns better - one thread per task, rather than trying to process all tasks.

Simon Marlow captured this well: http://stackoverflow.com/a/3858684/83805

"the abstractions that threads provide are essential for making server code easier to get right, and more robust"

JS has no support for these things, but you're right, when using languages (like Go) that do support this concept, it is very easy to write elegant code which can block locally without actually blocking the entire application, which allows you to write code that is far cleaner and easier to reason about.
The problem is javascript doesn't have support for this. That's why we see callbacks everywhere.