3 ms·
You certainly don't need promises for generators to act like coroutines. Take a look at how Python 2.5 handles generators; yield is an expression, and then the
by nostrademons 12y ago
You certainly don't need promises for generators to act like coroutines. Take a look at how Python 2.5 handles generators; yield is an expression, and then the external interface to a generator is a stream with a send() method you can use to resume the generator. (As another poster pointed out, a stream is a much more precise description of the abstraction than an array - arrays support constant-time random access, while streams are just ordered collections of elements.)
I do think that combining futures/promises with generators gives a much cleaner programming model. Take a look at how Python 3.4 handles generators & async programming; here a generator is implicitly a Future, and 'yield from' runs a future to completion, letting you compose coroutines regardless of how many yield points they have.
But my point is that these are all programming models, different ways to present the underlying abstraction to programmers. It's silly to talk about "the fact that coroutines require..." or "generators need promises" or "pretending that...", as if there were only one way to do async programming - these are not universal abstractions, they are models to present the underlying scheduler to programmers, and we choose between them based on how convenient they are to programmers.