In a previous article I demonstrated how a new feature from ES2016 (
await functions) could be used to help coordinate promises and execution.
However, we are instead able to use Generators (introduced in ES2015) to provide this feature, minus the syntactic sugar these two new keywords provide.
Passing in a Generator function and yielding in-place of
await, we are able to take advantage of the Generators control we have for resuming its execution.
This allows us to wait for the resolution or rejection of the yielded promise before continuing to the next yield or final value.
Below is a contrived example of using co-routines to coordinate the returned result of a collection of random promises (similar to a