-
-
Notifications
You must be signed in to change notification settings - Fork 6.4k
Description
Affected URL
https://nodejs.org/en/learn/asynchronous-work/overview-of-blocking-vs-non-blocking
Describe the issue in detail:
Hi everyone,
In the Overview of Blocking vs Non-Blocking article, section "Dangers of Mixing Blocking and Non-Blocking Code", a code example is given:
const fs = require('node:fs');
fs.readFile('/file.md', (err, data) => {
if (err) {
throw err;
}
console.log(data);
});
fs.unlinkSync('/file.md');It's followed by this text:
"In the above example, fs.unlinkSync() is likely to be run before fs.readFile(), which would delete file.md before it is actually read".
I tried the example, but while fs.unlinkSync() is indeed run before fs.readFile(), console.log(data) still outputs (despite the italized part above) the starting byte values of file.md, so it looks if file.md was first deleted and then read.
Could anyone explain to me how that is possible (or correct the article if it's worded poorly) please?
OS: Windows 10 Home 22H2,
Node.js v22.20.0, also tried v25.0.0 with the same result.
Metadata
Metadata
Assignees
Labels
Type
Projects
Status