Creates a response that streams data from an asynchronous generator.

  • Parameters

    • generator: AsyncGenerator<string | ArrayBuffer | Uint8Array, any, unknown>

      An asynchronous generator that yields chunks of data.

    • options: ResponseInit = {}

      Optional response initialization options.

    Returns Response

    A Response object that streams the data.

    Example usage:

    import { start, router, stream } from "@pulsar-http/core";

    const routes = [
    router.get("/stream", async () => {
    async function* dataGenerator() {
    yield "Hello, ";
    yield "World!";
    }

    return stream(dataGenerator());
    }),
    ];

    start({ routes });

    In this example, the response will stream the data "Hello, World!".