@epikodelabs/streamix / src/public-api / observeOn
Function: observeOn()
observeOn<
T>(context):Operator<T,T>
Defined in: projects/libraries/streamix/src/lib/operators/observeOn.ts:27
Creates a stream operator that schedules the emission of each value from the source stream on a specified JavaScript task queue.
This operator is a scheduler. It decouples the timing of value production from its consumption, allowing you to control when values are emitted to downstream operators. This is essential for preventing long-running synchronous operations from blocking the main thread and for prioritizing different types of work.
The operator supports three contexts:
"microtask": Emits the value at the end of the current task usingqueueMicrotask."macrotask": Emits the value in the next event loop cycle usingsetTimeout(0)."idle": Emits the value when the browser is idle usingrequestIdleCallback.
Timing caveat: values that the source produces before the downstream consumer attaches its first subscription are dropped. Start consuming the piped stream synchronously (or pair with shareReplay when replay is needed).
Type Parameters
T
T = any
The type of the values in the source and output streams.
Parameters
context
"microtask" | "macrotask" | "idle"
The JavaScript task queue context to schedule emissions on.
Returns
Operator<T, T>
An Operator instance that can be used in a stream's pipe method.