Saltar al contenido principal

Function: useInterval()

useInterval(callback, ms, immediate?): IntervalControl

Defined in: src/core/services/timing.service.ts:71

Repeatedly executes a callback at ms intervals with pause/resume/stop controls. Uses recursive setTimeout internally to avoid overlap.

Parameters

callback

() => void | Promise<void>

Function executed on each tick.

ms

number

Interval in milliseconds.

immediate?

boolean = false

If true, fires the callback immediately before the first interval (defaults to false).

Returns

IntervalControl

An IntervalControl with pause, resume, stop, and isRunning.

Example

const timer = useInterval(() => console.log("tick"), 1000);
setTimeout(() => timer.pause(), 3000);
setTimeout(() => timer.resume(), 5000);
setTimeout(() => timer.stop(), 10000);