DenoDDeno
Powered by
spirobelS
Denoβ€’3y agoβ€’
8 replies
spirobel

How to feed a ReadableStream / async Generator into a Response object?

`` Bun.serve({
    async fetch(req) {
        return new Response(
            async function* stream() {
                         // ~~~~~~~^?
                yield "Hello, ";
                yield Buffer.from("world!");
            },
        );
    },
});
`` Bun.serve({
    async fetch(req) {
        return new Response(
            async function* stream() {
                         // ~~~~~~~^?
                yield "Hello, ";
                yield Buffer.from("world!");
            },
        );
    },
});
it is possible to feed an async generator directly into the fetch Response with Bun. With deno this does not work. I also tried to turn it into a ReadableStream with ReadableStream.from(), but no success so far. Is this the correct way to produce a ReadableStream from an async generator, or do I have to do this differently? thanks!
image.png
Deno banner
DenoJoin
Chat about Deno, a modern runtime for JavaScript and TypeScript.
20,944Members
Resources
Recent Announcements

Similar Threads

Was this page helpful?

Similar Threads

How to stop reading from a ReadableStream?
1771771771177177177 / help
4y ago
ReadableStream to JSON
ZidanZZidan / help
4y ago
How to build a Response object with the 'url' property set
jcayzacJjcayzac / help
3y ago