tc39 / proposal-iterator-helpers

Methods for working with iterators in ECMAScript
https://tc39.es/proposal-iterator-helpers
1.33k stars 34 forks source link

Forkable generators #22

Closed dead-claudia closed 5 years ago

dead-claudia commented 5 years ago

I've got a related proposal that suggests forkable generators. I do specifically avoid having it generalized, because the behavior could be anywhere from unexpected to just plain wrong, and generator callees are not always written to potentially support cloning and replaying continuations with different next parameters.

The "Potential FAQs" section was written in part as a response to initial #tc39 IRC feedback, and I'm filing this issue based on a recommendation there.

devsnek commented 5 years ago

while generators themselves probably wouldn't be specified here, a lot of iterator libs have tee support, which might be interesting here.

dead-claudia commented 5 years ago

Yeah, but as noted in the "Potential FAQs" section, tee isn't in of itself sufficient. My .fork() is similar to a .tee(), but the key difference is that the side effects are replayed with results not buffered, where .tee() utilities only attempt them once and always buffer their results.

devsnek commented 5 years ago

closing as out of scope

jimmywarting commented 3 years ago

I trying to mimc ReadableStream.prototype.tee but with just plain asyncIterator instead and then i found this: https://stackoverflow.com/a/46416353/1008999

reason being is that i want to be able to handle both whatwg & node streams the same way.