- From: Takeshi Yoshino <notifications@github.com>
- Date: Sun, 22 Mar 2015 22:30:06 -0700
- To: whatwg/streams <streams@noreply.github.com>
- Message-ID: <whatwg/streams/pull/302/c84816393@github.com>
If the consumer of either branch really wants to interact with the original stream via `cancel()`, we should ensure that the consumer's `cancel()` call results in calling `cancel()` on the original stream. I basically think such needs should be taken care of by more complex custom tee-ing code. But if we're to build some helper for convenience (so that any change on the consumer code is unnecessary), I'd propose something like the following: - `rs.tee()` takes `cancelPropagator` - `rs.tee()` calls `cancelPropagator.init(cancel)` where `cancel` is a function that calls `rs.cancel()` - when the first branch is `cancel()`-ed, `cancelPropagator.handleFirst(reason)` is called where `reason` is the argument the consumer of the first branch passed to `cancel()` call. The return value of `handleFirst` is used for resolving the promise returned to the consumer of the first branch for its `cancel()` call - the same for the second branch - if `rs.tee()` is invoked without `cancelPropagator`, the default handler is used which is: ``` class DefaultCancelPropagator { constructor() { this._firstCancelled = false; this._secondCancelled = false; } init(cancel) { this._cancel = cancel; } handleFirst() { this._firstCancelled = true; if (this._secondCancelled) { this._cancel(); } return undefined; } handleSecond() { this._secondCancelled = true; if (this._firstCancelled) { this._cancel(); } return undefined; } } ``` --- Reply to this email directly or view it on GitHub: https://github.com/whatwg/streams/pull/302#issuecomment-84816393
Received on Monday, 23 March 2015 05:30:36 UTC