UNPKG

async-streamify

Version:

Stream and serialize nested promises and async iterables over HTTP, workers, etc

39 lines 1.14 kB
export type AsyncObjectSerializerOptions = { transformers?: ((value: unknown) => any)[]; }; /** * Extends the standard Response class to support streaming serialized objects * using AsyncObjectSerializer. The response is formatted as newline-delimited JSON (NDJSON). * * @example * ```typescript * // In a server handler * async function handler(req: Request) { * const data = { * status: "processing", * result: Promise.resolve({ completed: true }), * updates: (async function*() { * yield "step 1"; * yield "step 2"; * })() * }; * * return new AsyncResponse(data, { * headers: { * "cache-control": "no-cache" * } * }); * } * ``` */ export declare class AsyncResponse extends Response { /** * Creates a new AsyncResponse instance * * @param body - The object to serialize and stream, or null for an empty response * @param init - Standard ResponseInit options */ constructor(body: object | null, init?: ResponseInit, opts?: AsyncObjectSerializerOptions); } export default AsyncResponse; //# sourceMappingURL=response.d.ts.map