2 ms·
I'm not a fan of Node, but I think you've misunderstood how it works. Ignoring web workers, Node is a single threaded event loop based system. When you make an
by toast0 3y ago
I'm not a fan of Node, but I think you've misunderstood how it works. Ignoring web workers, Node is a single threaded event loop based system. When you make an i/o call with a callback, that can run the i/o call immediately as non-blocking ... if it suceeds or fails with a final error the callback can be called immediately (or queued for later, whatevs), if it returns EAGAIN, that fd is added to the event loop's select equivalent, and the next pending event is processed or the select is polled again. When that fd eventually is ready, your callback is called. This doesn't require multithreading.
Traditional Javascript is missing the basic concepts that allow for reasonable shared memory multithreading, if such a thing exists. WebWorkers allows for multithreading without shared memory. There's some ability to pass messages between workers and the main script, but I haven't explored this in Node.