Asynchronous iteration (for await...of)

We can use the new for...await...of expression to iterate and await each of the promises returned by an asynchronous iterator:

async function func() { 
    for await (const x of g1()) { 
        console.log(x); 
    } 
} 

Get Learning TypeScript 2.x - Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.