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
Should pipeTo return a promise for when the piping completes? #236
Comments
Currently, we have only Thinking of only (i), we can get notified of completion of reading from (a) is useful for type-(ii) I guess we give a different name to type-(ii) pipeTo even if we introduce it, so, I think it's ok to adopt the semantics (b) for Before in similar discussion I proposed making pipeTo return a tuple (or dictionary) of pipeToPromise and dest. But Domenic pointed out that it prevents chain style coding (a.pipeTo(b).pipeTo(c)). I'm just thinking if we can add pipeTo method to the object to return so that we can write the pipeTo chain. Do you think it works? |
I remember this now. The objection was slightly different though, since the chain is usually |
I see. Ah, we need to discuss also
Wow! |
I think the whole point of pipeThrough is to give a nice chainable sugar, so it should remain as-is. If you want to know more details you can manually do the pipeTo. |
Hmm, this is interesting. I didn't really think about this very much. I guess they could be reused if you didn't close either end? And you'd need to wait for them to finish flushing everything through? Kind of strange. |
For example, a DEFLATE-ing transform stream basically needs to be reset to use for another work since it has a compression context (LZ77 window remembering history for back-reference). So, I'd ask user to close I guess it's rare that we want to have data go through a transform stream and use it for another work without reset (where something (say, |
For that example I'd just create a new instance of the DEFLATE-ing transform stream :).
I think this could be accomplished, but you might have to drop down to trickier, primitives. E.g. either rewrite pipeTo yourself, or turn off all auto-closing/aborting/canceling, or use some sort of tee stream. No need to support it out of the box I think. |
So, in summary...
|
Oh, it's not fast-fail since Hmm, ... no, we have |
Yep :)
OK. Got it. |
In an offline thread, @acolwell was looking at a scenario where you'd do
rs.pipeTo(ws, { preventClose: true })
and wondering how to know when the piping was finished. This would be important for e.g. concatenating multiple readable streams into a writable stream.You could do this by monitoring
rs.closed
, but that feels a bit oblique and inverted. We could havepipeTo
return a promise that is fulfilled when the piping completes (or rejected if it errors).If we do this, would "piping completes" best correspond to (a) all data successfully read from
rs
; or (b) all data successfully written tows
? I would lean toward (b).The text was updated successfully, but these errors were encountered: