在下面的代码中,我希望mark-1在mark-2. 我猜,我不使用await和async正确的一些地方。
我很确定这一行:
const things = await fs.promises.readdir(folder);
和这条线
const stats = await fs.promises.stat(path);
是正确的,因为我们正在等待文件系统响应。
到目前为止,我并不关心错误检查或跨平台代码,只是让承诺正常工作
// Libraries
const fs = require('fs');
// API
getThings('_t/').then(() => {
console.log('mark-2')
})
// Accesses the file system and returns an array of files / folders
async function getThings (folder) {
const things = await fs.promises.readdir(folder);
things.forEach(async (thing)=>{
await getStats(thing, folder);
});
}
// Gets statistics for each file/folder
async function getStats (thing, folder) {
const path = folder + thing;
const stats = await fs.promises.stat(path);
console.log('mark-1');
}
沧海一幻觉
相关分类