4 ms·
If a function call in a node.js blocks, doesn't the app hang while waiting for it? A single process with event callbacks is almost the opposite of what is descr
by taybin 14y ago
If a function call in a node.js blocks, doesn't the app hang while waiting for it? A single process with event callbacks is almost the opposite of what is described here.
- jeremiep 14y agoIn node.js operation that would normally block are performed in a worker thread. For example to read a file you specify a filename and a callback function that will be called when the file is in memory. After the call the execution of the current thread will eventually return to the event loop and other events will be processed until the file is read, such as requests or other callbacks. Once the file is read, a call to the specified callback is queued on the event loop and then executed, resuming your code.
- ricardobeat 14y agoMy comment was specifically about module isolation and message-passing, the design patterns, not language implementation, preemptive vs cooperative or whatever.
- taybin 14y agoI hate to harp on this, since you were downvoted to oblivion, but node.js doesn't have module isolation, as a crash in one function will stop the entire program. And it doesn't have message-passing since it doesn't have multiple processes. There's nothing to pass messages to. The only design pattern it shares is splitting code into subsets, and every language (that matters) has that.
- ricardobeat 14y agoOn node.js: not if you use domains (0.8+) to isolate module exceptions, and you do (should) have multiple processes. On the client, a module throwing an error won't crash the browser either. Finally, events are a form of message-passing.