Asynchronous Iteration

Recall that an iterable object is an object that can be can be looped with the for-of loop.

Asynchronous iterator

An asynchronously iterable object is similar to a synchronously iterable object, except:

  • It has the [Symbol.asyncIterator] method instead of [Symbol.iterator]
  • Calling next() on the iterator returns a Promise instead of a value

Asynchronous generator

An asynchronous iterator can often be implemented using an async generator.

An async generator function (declared with async function*) allows you to use await and yield inside it. Any values that you yield inside an async generator are automatically wrapped in Promises.

References

  • JavaScript: The Definitive Guide, 7th Edition (David Flanagan)Chapter 13. Asynchronous JavaScript