Код: Выделить всё
async function getAllFiles(res, path) {
const files = Fs.readdirSync(path);
const users = [];
for (const file of files) {
const username = await getFileUser(path + file);
console.log("Start.");
console.log("username:");
console.log(username);
console.log("End.");
users.push(username);
}
const response = [files, users];
res.status(200).send(response);
}
username:
admin
End.
< /code>
Однако время от времени показывают следующие журналы: < /p>
admin
Start.
username:
undefined
End.
< /code>
, что я понятия не имею, как возможно. Сначала кажется, что он ничего не работает во всем петле, но асинхронная функция и строки, содержащие переменную, которая назначается с его значением? Чего мне не хватает?
Подробнее здесь: https://stackoverflow.com/questions/797 ... t-ot-times