[]previous and next page

createEventLog

Creates a bounded event log.

Creates a bounded event log. Use it in a stream handler to keep the last events and replay them to a client that reconnects with Last-Event-ID: log.since(stream.lastEventId).

Import#

ts
import { createEventLog } from "@shadow-js/dusk/server";

Signature#

ts
function createEventLog(options: { readonly capacity?: number } = {}): EventLog

Parameters#

Name Description
options The capacity (events kept). Default 1000.

Returns#

A log.

Throws#

  • RangeError when the capacity is not a positive integer.

Examples#

ts
const log = createEventLog({ capacity: 500 });
export function SSE(event, stream) {
  for (const missed of log.since(stream.lastEventId) ?? []) void stream.send({ id: missed.id, data: missed.data });
}