Skip to content

Commit 3d5d5cb

Browse files
DScheglovtshemsedinov
authored andcommitted
Upgrade fstat example: printing results only after all lstat requests have been processed (#1)
1 parent 3dbddbf commit 3d5d5cb

1 file changed

Lines changed: 3 additions & 2 deletions

File tree

JavaScript/4-error-fstat.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ const files = ['1-readFileSync.js', 'n-untitled.js', '3-async.js'];
66

77
const stats = new Array(files.length);
88

9-
const maxIndex = files.length - 1;
9+
let rest = files.length;
1010

1111
const printResult = () => {
1212
console.dir({ stats });
@@ -20,6 +20,7 @@ files.forEach((file, i) => {
2020
} else {
2121
stats[i] = stat;
2222
}
23-
if (i === maxIndex) printResult();
23+
if (--rest) return;
24+
printResult();
2425
});
2526
});

0 commit comments

Comments
 (0)