Reputation: 24406
Node.JS has synchronous versions for file operations:
fs.writeFileSync(file, data, ...)
According to this blog, the underlying OS call is still asynchronous (verified with DTrace), and all the sync version does is "block the event loop".
What does it mean to block the event loop (in purpose)? Is it something like continuous setImmediate() or something more low level?
Upvotes: 2
Views: 275
Reputation: 146064
What does it mean to block the event loop (in purpose)?
It just means v8 doesn't run any userland javascript code while waiting for the IO to complete. Normally v8 would be executing javascript while waiting for the IO, both your javascript and any libraries your application is using, but in this case it doesn't. One way to think of it is your entire program is paused while the IO happens, whereas normally your program continues to execute.
Upvotes: 1