concept generator in category react
appears as: generators,
Generators, generator

This is an excerpt from Manning's book Redux in Action.
We’re willing to bet that the last infinite loop you wrote was an accident. It happens to the best of us. In the case of generators however, infinite loops are a viable usage pattern. The next listing is an example of an intentional infinite loop.
It’s also possible to compose generators, or in other words, use generators within generators. In this case (listing 6.5), looping through the count function produces the numbers one through five in order as the count function becomes blocked until middleNumbers resolves. The yield* syntax is used to delegate out to another generator.
Listing 6.5. Composing generators example
function* count() { yield 1; yield 2; yield* middleNumbers(); #1 yield 5; } function* middleNumbers() { yield 3; yield 4; } #1 The middleNumbers generator completes before moving on to 5. !@%STYLE%@! {"css":"{\"css\": \"font-weight: bold;\"}","target":"[[{\"line\":3,\"ch\":36},{\"line\":3,\"ch\":38}],[{\"line\":12,\"ch\":0},{\"line\":12,\"ch\":2}]]"} !@%STYLE%@!