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

// 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();
原文地址:https://www.cnblogs.com/Answer1215/p/8468493.html