zenparsing / es6now

ECMAScript 6 to 5 Compiler and Runtime Environment
MIT License
29 stars 2 forks source link

Async Iteration Statement #30

Closed zenparsing closed 10 years ago

zenparsing commented 10 years ago

Should we create an async iteration statement? For example:

for (let line on readLines("some/file"))
    console.log(line);

How important is such a statement?

zenparsing commented 10 years ago

The for-of statement is expanded to enable iteration over async iterators.

Within an async function, we perform a nominal type check against the result of next, throw, or return. If the result is a Promise, then we await the result. Otherwise, we assume it must be an IteratorResult.

async function af() {
    for (let line of readLines("some/file"))
        console.log(line);
}