-
Notifications
You must be signed in to change notification settings - Fork 21
Description
I’m recommending that Observer implement next, return, and throw such that observers can participate in the same protocols that generators (and degenerate iterators) can.
Of particular note, pump is a utility that moves iterations from a producer to a consumer, pulling from the former and pushing to the latter. It can be forced to work with a generator, on the conceit that generators implement next, albeit with the wrong arrity.
https://github.com/endojs/endo/blob/master/packages/stream/index.js#L105
I do hope JS eventually supports generators with the appropriate arrity for observers, for example by function.sent https://github.com/tc39/proposal-function.sent (Though, I personally hope in a more polished form.)
In short, the duality of iterator and observer calls for API symmetry, at the very least on the grounds that it is easier to remember method names by analogy.