-
Notifications
You must be signed in to change notification settings - Fork 163
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 readable streams start right away? #269
Comments
This is kinda related to #146 (comment). I suggested removal of And, instead, I planned ... to propose some API to allow the user to tell the Stream to start/stop |
Sorry. I put a wrong issue ID in the last comment. Just fixed. |
In the Fetch's Response's case, the underlying source lives and is hidden in the Response? It doesn't look so weird if the |
3 comments above are about (2) of Domenic's first post, i.e. introducing "inert" state to the ReadableStream API. |
Agreed.
Agreed.
I think it's valid reasoning. But there's another point of view which is equally valid IMO, if you look only at the public API and not how it's implemented. Which is that, the
So I am OK with either a method (which kind of implies interpretation 1) or a getter (which kind of implies interpretation 2). |
Agreed. Ah, so, the proposal of mine is just a variant of (1) in your first post. |
Sorry, I don't understand. @tyoshino, do you still plan to add an API you mentioned at #269 (comment)? |
@yutakahirano I do. But it's just one of the solutions we have to address the issue (w3c/ServiceWorker#606). #269 (comment) which is elaborated by Domenic in #269 (comment) is categorized into approaches that add a trigger point to make the response "inert" to "non-inert" on the #269 (comment) is categorized into approaches that add a trigger point to do so on the Currently, I'm thinking we can go with the former approach. |
I think that, especially now that we have the flexibility provided by the separate |
Inspired by w3c/ServiceWorker#606, it occurs to me that this might be a more general problem.
Right now, creating a readable stream is intended to start the flow of data into it. At least one chunk should (eventually) be enqueued, to move the stream from
"waiting"
to"readable"
. If this never happens, then the stream never becomes readable, and is useless. In terms of the API, this manifests in how constructing the stream kicks off a call to the underlying source'sstart()
, and then ifstart()
succeeds we immediately callpull()
.However, there's another argument, which is that we want readable streams to be able to "represent" resources like HTTP request bodies or files. And in this case, it's often advantageous to have an "inert" request body or file object, which hasn't started doing any I/O (or at least hasn't done the "last mile" of I/O, e.g. IPC to move the chunks into the JS thread's process), until you ask it to.
In w3c/ServiceWorker#606 the current design seems to be guiding us toward the
Request
object being the "inert" request body, withreq.stream()
being a method that says "reify this into a JS-visible stream by doing IPC to get the chunks into the appropriate process." In that thread I phrased the two mental models as:.stream()
to reify the body as a stream, or.text()
to reify the body as text, etc."You could also imagine a similar situation for files, where e.g.
const file = fs.getFile("file.flac")
gives you an opaque file object without doing any I/O, allowing e.g.file.moveTo("/tmp")
but then alsofile.stream()
to start reifying the data as a stream. (This is not how Node.js'sfs
API works, for the record.)I see a few paths forward on this:
req.stream()
pattern.rs.start()
method (eww), or by makingrs.ready
start the flow (not great either)?read()
is a signal to start the flow of data, and the stream could avoid starting until that happens.I am leaning toward just keeping the current design, but I wanted to bring it up.
The text was updated successfully, but these errors were encountered: