您的位置:首页 > 大数据 > 人工智能

[ES2018] Two ways to write for-await-of

2018-02-25 01:47 621 查看
// Asynchronous iteration --> Symbol.asyncIterator
async function main() {
const syncIterable = [
Promise.resolve('a'),
Promise.resolve('b'),
];
for await (const x of syncIterable) {
console.log("x", x); // a, b
}

for (const s of await Promise.all(syncIterable)) {
console.log("s", s); // a, b
}
}

main();
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: