Better HN
top
new
best
ask
show
jobs
Log in
Sign up
Better HN
Comment
by
eurasiantiger
· 5y ago · 0 comments
There is already this:
for await (bar of foo) { }
Useful if you have an array of promises you want to handle sequentially.
Comments
[–]
fregante
5y ago
`for await` is for async iterables, which is different. The loop body will still block the loop. Compare it to the all/map example I wrote.
[–]
eurasiantiger
OP
5y ago
True, it is sequential and not parallel. I think this syntax with an async generator could be made to do what you seek.
[–]
fregante
5y ago
Async iterables are async generators. They call .next() on the iterable, that returns a promise, the promise resolves with either a new item to loop with, or with `done`, which will stop the loop.