|
|
|
|
|
by bastawhiz
3005 days ago
|
|
What you've written isn't invalid, it just does something different. Async iterators effectively yield awaitable promises instead of values. Iterators, normally, are synchronous. Generators immediately yield control to whatever is consuming from it. An async iterator yields things that will eventually yield control. The best example I can think of is disk IO. In Python you can iterate over a file handle, but in JS you can't (without blocking). Async iterators would enable this: each yielded promise would resolve with the next line of the file. Edit: the spec is pretty interesting: https://github.com/tc39/proposal-async-iteration/blob/master... |
|