DEV Community

Discussion on: JavaScript Iterators and Generators: Asynchronous Iterators

Collapse
 
chrisachard profile image
Chris Achard

Oh wow, this is next level! Also TIL about for-await-of; neat. Do you have some examples of where this can be really helpful in real world code? I'm wondering when I should think to maybe reach for this instead of cobbling something else together 😃 Thanks!

Collapse
 
jfet97 profile image
Andrea Simone Costa

Thanks, I'm glad you liked the article 😃

Generally, the async iteration is well suited for all those circumstances where consumers should have control over the flow of data.
Next time I'll show some more concrete examples thanks to async generators, but for now a good starting point to satisfy your needs surely are Node.js Readable streams. WHATWG Streams are async iterables too.

Collapse
 
eatsjobs profile image
Pasquale Mangialavori

I was thinking pagination could be a use case candidate for async iteration.

const page = await pagination[Symbol.asyncIterator]().next();
Collapse
 
jfet97 profile image
Andrea Simone Costa

Yes of course. I've already briefly mentioned it into the 'The consumer pressure problem' section 😃