SseStream
What a stream handler gets: the way to send, the request's Last-Event-ID, and the signal that aborts when the client disconnects or the stream is closed.
What a stream handler gets: the way to send, the request's Last-Event-ID, and the signal that
aborts when the client disconnects or the stream is closed.
Import#
ts
import type { SseStream } from "@shadow-js/dusk/server";
Signature#
ts
interface SseStream {
/**
* Sends one event. Resolves when the consumer has taken it (backpressure). Rejects with
* {@link SseOverflowError} when too many events wait for a consumer that does not read; the stream
* is closed then. A send after the stream closed does nothing.
*/
send(message: SseMessage | string): Promise<void>;
/**
* Writes a comment line (a keep-alive the browser ignores). At most 1 KiB of text, and nothing is written while an
* earlier chunk still waits for the consumer.
*/
comment(text?: string): void;
/** Ends the response. The handler may still run; its sends are ignored. */
close(): void;
/** Aborted when the client disconnects, the stream is closed or the stream fails. */
readonly signal: AbortSignal;
/** The `Last-Event-ID` the client sent when it reconnected, if any. */
readonly lastEventId: string | undefined;
/** True once the stream has closed (by close, disconnect or failure). */
readonly closed: boolean;
}
Members#
| Name | Type | Description |
|---|---|---|
send |
send(message: SseMessage | string): Promise<void> |
Sends one event. Resolves when the consumer has taken it (backpressure). Rejects with SseOverflowError when too many events wait for a consumer that does not read; the stream is closed then. A send after the stream closed does nothing. |
comment |
comment(text?: string): void |
Writes a comment line (a keep-alive the browser ignores). At most 1 KiB of text, and nothing is written while an earlier chunk still waits for the consumer. |
close |
close(): void |
Ends the response. The handler may still run; its sends are ignored. |
signal |
readonly signal: AbortSignal |
Aborted when the client disconnects, the stream is closed or the stream fails. |
lastEventId |
readonly lastEventId: string | undefined |
The Last-Event-ID the client sent when it reconnected, if any. |
closed |
readonly closed: boolean |
True once the stream has closed (by close, disconnect or failure). |