-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathawait.5.js
38 lines (31 loc) · 1.03 KB
/
await.5.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
const fs = require('fs');
const debug = require('debug')('async');
const currentDir = `${__dirname}`;
async function printFiles(){
debug(`Let's read all files in a directory!\n`);
let filenames;
try{
filenames = await fs.promises.readdir(currentDir);
}
catch(error) {
console.log(error);
};
const printFileActions = filenames.map(async function(filename) {
const stats = await fs.promises.lstat(filename);
if(stats.isFile()){
const file = await fs.promises.readFile(filename);
//Print File
debug(filename);
console.log('###################');
console.log(file.toString().slice(0,50));
console.log('###################\n\n');
}
});
Promise.all(printFileActions).then(() => {
console.log('Done')
});
}
printFiles().then(() => {
//When Will this happen?
debug('Callbacks!\n');
}).catch((error) => { console.log(error)});