Skip to content

API reference > @kontsedal/olas-realtime > createLiveStream

createLiveStream() function โ€‹

Subscribe to channel, buffer events into a ReadSignal<readonly TEvent[]> with capacity oldest-drop semantics and flushMs coalescing. The subscription lives inside ctx.effect so pause/resume re-runs it (we readisPaused.value as a tracked dep).

Naming: the create* prefix is the convention for ctx-taking composables (createPersisted, createRealtimePatcher). The define* prefix is reserved for module-scope factories (defineQuery, defineController).

Buffer semantics (SPEC ยง16.5): - capacity caps memory; oldest entries drop when exceeded. - flushMs coalesces N events into one signal write โ€” prevents thrashing under 1000-events/sec bursts. flushMs <= 0 flushes synchronously. - pause() tears down the subscription; already-buffered events survive, but events arriving DURING the pause are LOST (not received). Recover a gap with onReconnect(...) + query invalidate, not the buffer. - clear() resets the buffer (and any unflushed pending events) without touching the subscription. - channel is a name or a signal of one. A new name moves the subscription to the new channel and empties the buffer, as clear() does: a tail holds one channel's events, and nothing in an event says which channel it came from. A change during a pause empties it too, and resume() subscribes to the new name.

Signature:

typescript
export declare function createLiveStream<TEvent>(ctx: Ctx<RealtimeDeps>, channel: string | ReadSignal<string>, options?: LiveStreamOptions<TEvent>): LiveStream<TEvent>;

Parameters โ€‹

Parameter

Type

Description

ctx

Ctx<RealtimeDeps>

channel

string | ReadSignal<string>

options

LiveStreamOptions<TEvent>

(Optional)

Returns:

LiveStream<TEvent>

Released under the MIT License.