Use node:timers
↗ APIs to schedule functions to be executed later.
This includes setTimeout
↗ for calling a function after a delay,
setInterval
↗ for calling a function repeatedly,
and setImmediate
↗ for calling a function in the next iteration of the event loop.
import timers from "node:timers" ;
timers . setTimeout ( () => {
timers . setTimeout ( () => {
import timers from "node:timers" ;
timers . setTimeout ( () => {
timers . setTimeout ( () => {
Note
Due to security-based restrictions on timers in Workers,
timers are limited to returning the time of the last I/O. This means that while setTimeout, setInterval, and setImmediate will defer your function execution
until after other events have run, they will not delay them for the full time specified.
Note
When called from a global level (on globalThis
↗ ),
functions such as clearTimeout
and setTimeout
will respect web standards rather than Node.js-specific functionality. For complete Node.js
compatibility, you must call functions from the node:timers
module.
The full node:timers
API is documented in the Node.js documentation for node:timers
↗ .
Thank you for helping improve Cloudflare's documentation!