Function: toAsyncIter()¶
function toAsyncIter(response, signal): AsyncGenerator<{
data: string;
id?: string | null;
type: "message" | "status" | "heartbeat" | "disconnect";
}>;
Defined in: rine-ts-sdk/src/utils/sse.ts:38
Convert a fetch Response with an SSE body into an AsyncIterable of RineEvent.
Parameters¶
| Parameter | Type | Description |
|---|---|---|
response |
Response |
A fetch Response whose body is an SSE stream. |
signal |
AbortSignal |
AbortSignal for cancellation. Usage: const resp = await fetch(url, { headers: { Accept: 'text/event-stream' } }); for await (const event of toAsyncIter(resp, signal)) { console.log(event.type, event.data); } |
Returns¶
AsyncGenerator\<{
data: string;
id?: string | null;
type: "message" | "status" | "heartbeat" | "disconnect";
}>