Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

consider allowing a stream to be removed from a pipeline #307

Open
wanderview opened this issue Mar 26, 2015 · 4 comments
Open

consider allowing a stream to be removed from a pipeline #307

wanderview opened this issue Mar 26, 2015 · 4 comments
Labels
Milestone

Comments

@wanderview
Copy link
Member

Talking with @trevnorris, it sounds like it would be useful to allow a stream to be removed from a pipeline as an optimization.

For example, if a.pipeThrough(b).pipeTo(c), remove b at some point so a goes straight to c.

This optimization is particularly useful if a and c are native C++ implementations and removing b means its not necessary to execute javascript any more.

Potential APIs for this would be b.collapse() or perhaps b could return a special value from its write or read methods signalling it should be removed from the pipe chain.

@tyoshino
Copy link
Member

Can you elaborate the use case? Initially we need b but at some point b becomes unnecessary?

What's going on in piping is basically not observable from the streams API. Which of the objects tells the timing to collapse b?

@wanderview
Copy link
Member Author

The example I was provided was a processor which decrypts cookies in a network stream. Once the cookies have passed they want only the native C++ stream processors operating for the rest of the http response body. Bouncing through js for a function that will never do anything forces a de-opt.

@tyoshino
Copy link
Member

If the cookie decrypter is designed to become "closed" when it sees the end of headers, we can use pipeTo with the preventCancel parameter set to true to get notified when the decrypter finishes consuming headers, but without cancel()-ing the source. The decrypter needs to have a method to returns unconsumed data written by pipeTo so that the user can write the data to the body receiver first before resuming pipeTo from the source to the body receiver.

This is handled as non-purposeful closure (https://github.com/whatwg/streams/blob/master/reference-implementation/lib/readable-stream.js#L79), so, we might need to change this line, ... or, making the decrypter "closed" may be a wrong approach.


Another approach:

The decrypter starts exerting backpressure not to receive data from the network stream anymore. cookieDecrypter.ready becomes fulfilled, and then the user cancels the pipeTo. Then, re-pipeTo the body receiver after giving the unused data retrieved from cookieDecrypter.

@wanderview
Copy link
Member Author

@trevnorris, does the above address your use case?

@domenic domenic added the piping label Nov 29, 2016
@domenic domenic modified the milestone: V2 Mar 30, 2017
@annevk annevk removed the question label May 28, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Development

No branches or pull requests

4 participants