News for hackers. Stuff that matters.
Re:V8 adds support for top-level await by drevil-v2 on Tuesday September 24, 2019 @08:32PM (#21066327)
Well I personally would use a synchronous method rather than async for something like that where the next code path depends on the return data; if you can't get the file contents then you want to throw an error straight away.
Re:V8 adds support for top-level await by galaxyLogic on Tuesday September 24, 2019 @09:57PM (#21066817)
That would seem to make sense, using readFileSync() instead.

I assume it would really do much the same thing as the await example. Is there any difference?

If they do the same thing, then what's the benefit of async/await? I guess it's that you can now write your own "fs.readFileSync()" or something like that in JavaScript when needed.

Re:V8 adds support for top-level await by jeswin on Tuesday September 24, 2019 @10:56PM (#21067153)
fs.readFileSync() blocks the event loop preventing any other code from being run or other events/requests from being processed. Await yields control back so that other requests can be processed while the file is being read.
Re:V8 adds support for top-level await by galaxyLogic on Wednesday September 25, 2019 @09:54AM (#21070773)
Ah I see. Genius. So is there ever a use-case for NOT using the Async/Await -version of readFile()? Is fsReadSync() now just legacy which we don't need any more?