9 ms·
If all async functions are immediately awaited, there is only one thread of execution - no concurrency. If they are not awaited, someone has to manage an array
by harikb 5y ago
If all async functions are immediately awaited, there is only one thread of execution - no concurrency.
If they are not awaited, someone has to manage an array/list of promises.
Is there a worker model where the worker can work on a series of tasks?
- sudhirj 5y agoThe event loop will queue these up for you, but it should be possible to build a queuing library over this. What kind of API did you have in mind?
- deleted 5y ago[deleted]
- hn_throwaway_99 5y ago> If all async functions are immediately awaited, there is only one thread of execution - no concurrency. In a Node web server process, though, this isn't really true. If you perform a CPU intensive task on the main event loop, all other incoming requests will pause. Using worker threads instead turns that CPU task into, for all intents and purposes, an async io call, freeing the main event loop to handle concurrent incoming requests. Since handling CPU intensive tasks is the main downside of a Node web app, I think this library is a great solution for that (I think this library's API is a much easier to use wrapper around native Worker threads).