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
What is the expected behaviour of .pipeThrough()? #765
Comments
If you want to know about the precise behavior, you should read the spec, not the note boxes that are intended as a gentle introduction. The spec is very simple: it is the four steps at https://streams.spec.whatwg.org/#rs-pipe-through Please let us know if you have any questions after reading and understanding the spec. |
@domenic At this point, no, still do not understand the pattern. Can you illuminate the errors of usage at OP so can correct? |
Can you explain what you mean by "processed first" then? |
From an evidently naive interpretation the data from the What does returns mean within the specification? Do we specifically What are examples of |
I don't know what "available first" means. Code would help, with expected results and actual results. |
Oh, I think I missed your The issue is that pull() is called whenever a readable stream is created. If you have no data to give back, then don't call controller.enqueue(). But you always need to be prepared for pull() being called. |
@domenic http://plnkr.co/edit/uqbvxUQtjXEpcPYQjD2i?p=preview Why is Expected result is to How do we defer This is what mean by request for basic working example. For those who may interpret specification literally when trying to comprehend how to properly use |
Probably you didn't see my above comment, but it's the same reason: because pull() is called as soon as the readable stream is created. Just remove the pipeThrough line entirely and that becomes clear. |
@domenic So do we utilize |
No. pull() will always be called as long as the current size of the queue is less than the high water mark. You can set the high water mark to zero if you really want to avoid pull() calls, but that's not recommended. It's better to just write a well-behaved pull() that can be called any time. Trying to control when it's called is not a good idea here. |
@domenic Then what am missing, here? Should just continue to try different configuration on own? Or avoid using Have no experience using high water mark and also have questions about |
So the basic problem is that manually creating a transform stream is very hard. You may enjoy looking through https://github.com/whatwg/streams/blob/master/reference-implementation/lib/transform-stream.js, which we're attempting to clean up and eventually standardize and ship. When it's ready, you'll be able to create something simple like const { readable, writable } = new TransformStream({
transform(chunk) {
return chunk.map(c => c * 10);
}
}); Until then, properly understanding how to get data from the writable side to the readable side of a transform is tricky. Your version has a variety of bugs, but even after I cleaned them up, it turns out it doesn't work, because pull() is called when there is no chunk written to the writable side, and is not called after that, so it never makes it to the readable side. Here is a demo if this not working well: http://jsbin.com/yowoqozavo/1/edit?html,console Here is a version that works, using a very different technique: http://jsbin.com/hicawawizo/edit?html,console I don't really recommend manually creating transform streams yourself. Manually creating { readable, writable } pairs makes sense for some cases, known as "duplex" streams, where there are two separate I/O channels: see e.g. https://streams.spec.whatwg.org/#example-both. But for transformations of data, you'll really want to use transform-stream.js, and eventually, the browser's built-in TransformStream. |
No. close() is only present if you want to perform special actions in response to closing. |
Returning to the original question, pipeThrough is approximately equivalent to function pipeThrough({writable, readable}) {
this.pipeTo(writable);
return readable;
} Key to this discussion is that pipeThrough() does not create any link between |
@ricea Was able to achieve requirement using
and by compiling the files at https://github.com/whatwg/streams/blob/master/reference-implementation/lib/ into a single file and using
|
According to the specification
3.2.4.4. pipeThrough({ writable, readable }, options)
Seeking clarification as to what the above paragraph means for practical usage.
Specifically, the literal text appears to suggest that the
writable
side of the object would be processed first.Perhaps have a general misinterpretation of the intended usage of the
.pipeThrough()
method, here.Given
the expected result initially here was that
writable
would be processed first, thoughreadable
is processed first.If the specification is taken literally, how do we access the data transformed at
writable
side at thereadable
side of the pair?Can we
return
data from aWritableStream
to aReadableStream
?Can we create a basic example of the practical intended and correct usage of the
pipeThrough
method; both as the current implementation at browsers exist, and, if applicable, how the current implementation at browsers differs from what the specification authors and contributors are ultimately working towards implementing at browsers?The text was updated successfully, but these errors were encountered: