-
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
Introspection: disturbed or locked #1105
Comments
See also #1025. |
Do you think unusable is a reasonable name or would you want something else? It would be nice to avoid having to rename |
Does this mean that |
@ricea it's not a public API and if there was to be a public API it should be on |
Oh, sorry, I misunderstood. We've discourage the use of |
Interesting, could Fetch have used something else? |
I wasn't involved in the original discussion, but if I understand it correctly it was a compromise to ensure that |
Looks like yutakahirano/fetch-with-streams#13 has some background and w3c/ServiceWorker#452 (comment) also goes into it. Still not sure I understand why other APIs would not want the same kind of guarantees. Seems @domenic might know as well. (I was involved, but I have forgotten most of that...) |
It's hard to read those old threads, as I've lost a lot of the context and it seems like we didn't have the notion of exclusive readers at the time I will say that I continue to believe So my inclination for now is that it's best not to add more conveniences around this somewhat-legacy corner of the streams/fetch spec intersection. As @yutakahirano says in #1025, what people are most interested in is validity of a stream, which is only tangentially connected to whether it's been disturbed, and is usually format-specific. |
I agree with @domenic that we shouldn't add more conveniences around "disturbed". I think, if I were to design the Unfortunately, we can't remove |
That's what File API does (though it's also a bit different as it doesn't have to care about letting things be read once). So the problem is not so much But we also use this when extracting, e.g., when constructing a |
Hmm, good point. I don't see why you shouldn't be allowed to construct a For example, it's already possible to create a non-disturbed let rs1 = new ReadableStream({
start(c) {
c.enqueue(new Uint8Array([1, 2, 3]));
c.enqueue(new Uint8Array([4, 5, 6]));
c.enqueue(new Uint8Array([7, 8, 9]));
c.close();
}
});
// Disturb the stream
let reader1 = rs1.getReader();
await reader1.read(); // { done: false, value: Uint8Array([1, 2, 3]) }
reader1.releaseLock();
new Response(rs1); // throws TypeError: "Response body object should not be disturbed or locked"
// Create a "fresh" stream that continues from rs1
let rs2 = rs1.pipeThrough(new TransformStream());
// or: let [rs2, rs3] = rs1.tee(); rs3.cancel();
let resp = new Response(rs2); // works
await resp.arrayBuffer(); // ArrayBuffer([4, 5, 6, 7, 8, 9]) Once we have new Response(rs1) // throws
new Response(ReadableStream.from(rs1)) // ok Does anyone have any idea why we have this restriction? 🤷♂️ |
I ran blame and found whatwg/fetch#792. It suggests we could possibly remove it for |
After having just gone through the implementation for Node.js core, I'd definitely be +1 on a |
Fetch has a couple cases where it needs to check whether a stream is disturbed or locked. Is this something that other consumers of Streams need?
For Fetch's Body mixin I plan to introduce a term for this condition: "unusable" (see whatwg/fetch#1155), but it would still be useful to have a term that's applicable to
ReadableStream
objects as well and ideally that name would be shared.The text was updated successfully, but these errors were encountered: