April 2018
Beginner
536 pages
13h 21m
English
We have already learned about the interface that is implemented by all iterators:
interface Iterator<T> {
next(value?: any): IteratorResult<T>;
return?(value?: any): IteratorResult<T>;
throw?(e?: any): IteratorResult<T>;
}
However, we haven't yet learned about the interface that is implemented by all asynchronous iterators:
interface AsyncIterator<T> {
next(value?: any): Promise<IteratorResult<T>>;
return?(value?: any): Promise<IteratorResult<T>>;
throw?(e?: any): Promise<IteratorResult<T>>;
}
An asynchronous iterator returns a promise every time we invoke the next method. The following code snippet demonstrates how asynchronous iterators can be very useful when used in conjunction with asynchronous functions: