Skip to content

@epikodelabs/streamix


@epikodelabs/streamix / dom/src/public-api / onIdle

Function: onIdle()

onIdle(timeout?): Stream<IdleDeadline>

Defined in: projects/libraries/streamix/dom/src/lib/streams/onIdle.ts:24

Creates a reactive stream that emits IdleDeadline objects whenever the browser enters an idle period.

This stream is useful for scheduling low-priority work such as:

  • background computations
  • prefetching
  • cache warming
  • non-urgent state updates

Behavior:

  • Starts a shared idle loop when the first subscriber subscribes.
  • Emits the IdleDeadline object provided by requestIdleCallback.
  • Continues scheduling idle callbacks until all subscribers unsubscribe.
  • Falls back to setTimeout when requestIdleCallback is unavailable.
  • Safe to import and subscribe in SSR (no-op).
  • Fully compatible with async iteration.

Parameters

timeout?

number

Optional timeout (ms) after which idle callback must fire.

Returns

Stream<IdleDeadline>

A stream emitting idle deadlines.

Released under the GNU AGPL v3 or later.