spirobelS
Denoβ€’2y 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!");
            },
        );
    },
});
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
Was this page helpful?