function
timers.promises.setInterval
delay?: number,
value?: T,
): AsyncIterator<T>;
Returns an async iterator that generates values in an interval of delay ms. If ref is true, you need to call next() of async iterator explicitly or implicitly to keep the event loop alive.
import {
setInterval,
} from 'node:timers/promises';
const interval = 100;
for await (const startTime of setInterval(interval, Date.now())) {
const now = Date.now();
console.log(now);
if ((now - startTime) > 1000)
break;
}
console.log(Date.now());@param delay
The number of milliseconds to wait between iterations. Default: 1.
@param value
A value with which the iterator returns.
Referenced types
interface TimerOptions
- ref?: boolean
Set to
falseto indicate that the scheduledTimeoutshould not require the Node.js event loop to remain active.