Skip to main content

setClockInterval()

setClockInterval(cb, ms): () => void

Works the same way as setInterval but will wait to fire until next clock second.

Parameters

cb

() => void

The callback to execute immediately and after each duration.

ms

number

The time, in ms, between callback execution.

Returns

Function

A function to clear the timeout.

Returns

void

Example

const cleanup = setClockInterval(() => console.log('hi'), 250);
// will log hi every 250ms starting on next clock second