Hacker News new | ask | show | jobs
by cedias 4576 days ago
I'm puzzled, what's the use case for threads in the node asynchronous model ? Isn't the major use of threads is to prevent long running task from blocking the app in synchronous programming ?
3 comments

IO is asynchronous, but code execution is not asynchronous. If a block of code is doing intensive math for 100ms, then that blocks the whole process, and potentially other IO, from executing in that 100ms.

Perhaps you should think of node as "event-driven" rather than "asynchronous".

CPU-bound loads still block the event loop. Modules take care of this behind the scenes (sometimes?) but if you're rolling your own expensive operation threads can come in handy.
Sometimes you need to do a lot of CPU work which the async I/O model will never help with.