April 2018
Beginner
536 pages
13h 21m
English
If we invoke a function in TypeScript, we can assume that once the function starts running, it will always run to completion before any other code can run. However, a new kind of function that may be paused in the middle of execution—one or many times—and resumed later, allowing other code to run during these paused periods, has recently been added to the ECMAScript specification. These new kinds of functions are known as generators.
A generator represents a sequence of values. The interface of a generator object is just an iterator. An iterator implements the following interface:
interface Iterator<T> {
next(value?: any): IteratorResult<T>;
return?(value?: any): IteratorResult<T>;
throw?(e?: any): IteratorResult<T>;
}
The next() ...