Re:V8 adds support for top-level await
by ihuman on Tuesday September 24, 2019 @08:35PM
(#21066352)
Is there an advantage to using "await fs.readFile" over "fs.readFileSync"?
[ Parent
| on HN ]
You haven't blocked the entire event loop (i.e., other async functions that may be waiting on I/O) while the file is being read.
Re:V8 adds support for top-level await
by hombre_fatal on Tuesday September 24, 2019 @11:09PM
(#21067225)
Synchronous code blocks the event loop, so in real world code you'd only use the sync-version in some special cases, like when you're reading config files before you "server.boot()" and other scenarios where it's just a one-time cost.
Though the few sync functions in the stdlib become less and less convenient, first when promises came out, then with async/await, and now with top-level await.