Skip to content

@epikodelabs/streamix


@epikodelabs/streamix / src/public-api / timer

Function: timer() ​

timer(delayMs?, intervalMs?): Atom<number>

Defined in: projects/libraries/streamix/src/lib/factories/timer.ts:23

Creates a hot timer atom that emits numbers starting from 0.

The underlying timer is shared between all subscribers. It starts on the first subscription and stops when the last subscriber unsubscribes. As with every Atom, a new subscriber receives the timer atom's current value first when one exists; earlier history is not replayed.

In analog mode each subscriber keeps only the latest value (skipping intermittent ticks); in discrete mode each subscriber queues all values.

Parameters ​

delayMs? ​

number = 0

The time in milliseconds to wait before emitting the first value (0). If 0, the first value is emitted immediately (in the next microtask).

intervalMs? ​

number

The time in milliseconds between subsequent emissions. If not provided, it defaults to delayMs, which means timer(100) keeps emitting every 100 ms indefinitely. (RxJS timer(due) emits once and completes; use take(1) for that behavior here.)

Returns ​

Atom<number>

An atom that emits incrementing numbers (0, 1, 2, ...).

Released under the MIT License.