let response = await fetch(url);
for await (let chunk of response.body) {
// ...
}
Currently failing with error TS2504: Type 'Body' must have a '[Symbol.asyncIterator]()' method that returns an async iterator.
This feature would require implementing parts of the Streams API, for example, ReadableStream and related classes.
@ry What are your thoughts on the Streams API? Should it be supported in Deno eventually?
fetch should be compatible with web APIs - so we should do it. It should be straightforward - all the infrastructure is in place to do this. I believe ResponseBody is already a "Writer", for example.
What are your thoughts on the Streams API?
I think it's poorly designed - which is why we have Reader and Writer in Deno.
I think it's poorly designed
I agree that it's more complicated than Deno's API, but is it really so bad that we don't ever want to support it? I think for this use-case, for example, it's actually fairly similar.
// Deno API
let { eof, nread } = await response.body.read(buffer)
// Streams API
let reader = response.body.getReader({ mode: 'byob' })
let { done, value } = await reader.read(buffer)
Personally, I'd like Deno to be compatible with the Streams API to be even more browser-friendly. On one hand, the Streams API is still fairly experimental so it might be best to wait. On the other hand, I can also imagine that, whenever the Streams API is stable, we have 3 major competing JS stream APIs (Web, Node, Deno) further fragmenting the JS ecosystem.
We must support it to be browser compatible . See toAsyncIterator() for an example of how to convert between Reader and ReadableStream
Most helpful comment
We must support it to be browser compatible . See toAsyncIterator() for an example of how to convert between Reader and ReadableStream