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.
I’m recommending that
Observerimplementnext,return, andthrowsuch that observers can participate in the same protocols that generators (and degenerate iterators) can.Of particular note,
pumpis 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 implementnext, 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.senthttps://github.com/tc39/proposal-function.sent (Though, I personally hope in a more polished form.)In short, the duality of
iteratorandobservercalls for API symmetry, at the very least on the grounds that it is easier to remember method names by analogy.