Skip to content

Stream

Stream: object

Defined in: Core/Stream.ts:42

emit: <S, K>(target, message) => void = emitStream

Emits a message payload to one or more target streams.

Uses a synchronous breadth-first trampoline queue to handle re-entrant emissions deterministically.

S extends Record<string, unknown>

K extends string

Stream<S> | readonly Stream<S>[]

WithKind<K> & WithValue<S[K]>

void

Stream.emit(streamA, {
  kind: "userLoggedIn",
  value: { userId: "user-1" },
});

Stream.emit([streamA, streamB], {
  kind: "userLoggedIn",
  value: { userId: "user-1" },
});

forward: <S>(options) => () => void = forwardStream

Forwards messages from one stream to another (or multiple).

S extends Record<string, unknown>

ForwardOptions<S>

() => void

const stop = Stream.forward({
  from: authStream,
  to: analyticsStream,
  only: ["userLoggedIn"],
});

listen: <S, K>(stream, events, options?) => ListenerBuilder<S> = listenStream

Initiates listener registration on a stream for specific event kind(s) or sequence.

S extends Record<string, unknown>

K extends string

Stream<S>

K | readonly K[]

SequenceOptions<S>

ListenerBuilder<S>

const sub = Stream.listen(
  appStream,
  ["userLoggedIn", "checkoutStarted"],
  { ordered: true }
).reduce(
  (msg, state) => ({ count: state.count + 1 }),
  { count: 0 }
);

make: <S>(options?) => Stream<S> = makeStream

Constructs a new Stream instance.

S extends Record<string, unknown>

Options

Stream<S>

const stream = Stream.make<AppMessages>({ name: "app" });