{"$schema":"https://doc-kit.nodejs.org/schemas/api-doc/1.0.0.json","id":"timers","path":"/timers","type":"module","module":"timers","title":"Timers","introducedIn":"v0.10.0","sourceLink":{"path":"lib/timers.js","url":"https://github.com/nodejs/node/blob/HEAD/lib/timers.js"},"stability":{"index":"2","description":"Stable"},"added":[],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"description":"The `timer` module exposes a global API for scheduling functions to\nbe called at some future period of time. Because the timer functions are\nglobals, there is no need to call `require('node:timers')` to use the API.\n\nThe timer functions within Node.js implement a similar API as the timers API\nprovided by Web Browsers but use a different internal implementation that is\nbuilt around the Node.js [Event Loop](https://nodejs.org/learn/asynchronous-work/event-loop-timers-and-nexttick#setimmediate-vs-settimeout).","summary":"The `timer` module exposes a global API for scheduling functions to be called at some future period of time. Because the timer functions are globals, there is no need to call `require('node:timers')` to use the API.","examples":[],"children":[{"kind":"class","id":"class-immediate","name":"Immediate","title":"Class: `Immediate`","scope":"module","overloadOf":null,"stability":null,"added":[],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"extends":null,"description":"This object is created internally and is returned from [`setImmediate()`](#setimmediatecallback-args). It\ncan be passed to [`clearImmediate()`](#clearimmediateimmediate) in order to cancel the scheduled\nactions.\n\nBy default, when an immediate is scheduled, the Node.js event loop will continue\nrunning as long as the immediate is active. The `Immediate` object returned by\n[`setImmediate()`](#setimmediatecallback-args) exports both `immediate.ref()` and `immediate.unref()`\nfunctions that can be used to control this default behavior.","summary":"This object is created internally and is returned from `setImmediate()`. It can be passed to `clearImmediate()` in order to cancel the scheduled actions.","examples":[],"children":[{"kind":"method","id":"immediatehasref","name":"hasRef","title":"`immediate.hasRef()`","scope":"module","overloadOf":null,"stability":null,"added":["v11.0.0"],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"signature":{"parameters":[],"returns":{"type":{"text":"boolean","links":[{"name":"boolean","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#boolean_type","start":0,"end":7}]},"description":""}},"description":"If true, the `Immediate` object will keep the Node.js event loop active.","summary":"If true, the `Immediate` object will keep the Node.js event loop active.","examples":[],"children":[]},{"kind":"method","id":"immediateref","name":"ref","title":"`immediate.ref()`","scope":"module","overloadOf":null,"stability":null,"added":["v9.7.0"],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"signature":{"parameters":[],"returns":{"type":{"text":"Immediate","links":[{"name":"Immediate","href":"timers.html#class-immediate","start":0,"end":9}]},"description":"a reference to `immediate`"}},"description":"When called, requests that the Node.js event loop *not* exit so long as the\n`Immediate` is active. Calling `immediate.ref()` multiple times will have no\neffect.\n\nBy default, all `Immediate` objects are \"ref'ed\", making it normally unnecessary\nto call `immediate.ref()` unless `immediate.unref()` had been called previously.","summary":"When called, requests that the Node.js event loop _not_ exit so long as the `Immediate` is active. Calling `immediate.ref()` multiple times will have no effect.","examples":[],"children":[]},{"kind":"method","id":"immediateunref","name":"unref","title":"`immediate.unref()`","scope":"module","overloadOf":null,"stability":null,"added":["v9.7.0"],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"signature":{"parameters":[],"returns":{"type":{"text":"Immediate","links":[{"name":"Immediate","href":"timers.html#class-immediate","start":0,"end":9}]},"description":"a reference to `immediate`"}},"description":"When called, the active `Immediate` object will not require the Node.js event\nloop to remain active. If there is no other activity keeping the event loop\nrunning, the process may exit before the `Immediate` object's callback is\ninvoked. Calling `immediate.unref()` multiple times will have no effect.","summary":"When called, the active `Immediate` object will not require the Node.js event loop to remain active. If there is no other activity keeping the event loop running, the process may exit before the `Immediate` object's callback is invoked. Calling `immediate.unref()` multiple times will have no effect.","examples":[],"children":[]},{"kind":"method","id":"immediatesymboldispose","name":"[Symbol.dispose]","title":"`immediate[Symbol.dispose]()`","scope":"module","overloadOf":null,"stability":null,"added":["v20.5.0","v18.18.0"],"deprecated":[],"removed":[],"napiVersion":[],"changes":[{"versions":["v24.2.0"],"prUrl":"https://github.com/nodejs/node/pull/58467","commit":null,"description":"No longer experimental."}],"signature":{"parameters":[],"returns":null},"description":"Cancels the immediate. This is similar to calling `clearImmediate()`.","summary":"Cancels the immediate. This is similar to calling `clearImmediate()`.","examples":[],"children":[]}]},{"kind":"class","id":"class-timeout","name":"Timeout","title":"Class: `Timeout`","scope":"module","overloadOf":null,"stability":null,"added":[],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"extends":null,"description":"This object is created internally and is returned from [`setTimeout()`](#settimeoutcallback-delay-args) and\n[`setInterval()`](#setintervalcallback-delay-args). It can be passed to either [`clearTimeout()`](#cleartimeouttimeout) or\n[`clearInterval()`](#clearintervaltimeout) in order to cancel the scheduled actions.\n\nBy default, when a timer is scheduled using either [`setTimeout()`](#settimeoutcallback-delay-args) or\n[`setInterval()`](#setintervalcallback-delay-args), the Node.js event loop will continue running as long as the\ntimer is active. Each of the `Timeout` objects returned by these functions\nexport both `timeout.ref()` and `timeout.unref()` functions that can be used to\ncontrol this default behavior.","summary":"This object is created internally and is returned from `setTimeout()` and `setInterval()`. It can be passed to either `clearTimeout()` or `clearInterval()` in order to cancel the scheduled actions.","examples":[],"children":[{"kind":"method","id":"timeoutclose","name":"close","title":"`timeout.close()`","scope":"module","overloadOf":null,"stability":{"index":"3","description":"Legacy: Use [`clearTimeout()`](#cleartimeouttimeout) instead."},"added":["v0.9.1"],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"signature":{"parameters":[],"returns":{"type":{"text":"Timeout","links":[{"name":"Timeout","href":"timers.html#class-timeout","start":0,"end":7}]},"description":"a reference to `timeout`"}},"description":"Cancels the timeout.","summary":"Cancels the timeout.","examples":[],"children":[]},{"kind":"method","id":"timeouthasref","name":"hasRef","title":"`timeout.hasRef()`","scope":"module","overloadOf":null,"stability":null,"added":["v11.0.0"],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"signature":{"parameters":[],"returns":{"type":{"text":"boolean","links":[{"name":"boolean","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#boolean_type","start":0,"end":7}]},"description":""}},"description":"If true, the `Timeout` object will keep the Node.js event loop active.","summary":"If true, the `Timeout` object will keep the Node.js event loop active.","examples":[],"children":[]},{"kind":"method","id":"timeoutref","name":"ref","title":"`timeout.ref()`","scope":"module","overloadOf":null,"stability":null,"added":["v0.9.1"],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"signature":{"parameters":[],"returns":{"type":{"text":"Timeout","links":[{"name":"Timeout","href":"timers.html#class-timeout","start":0,"end":7}]},"description":"a reference to `timeout`"}},"description":"When called, requests that the Node.js event loop *not* exit so long as the\n`Timeout` is active. Calling `timeout.ref()` multiple times will have no effect.\n\nBy default, all `Timeout` objects are \"ref'ed\", making it normally unnecessary\nto call `timeout.ref()` unless `timeout.unref()` had been called previously.","summary":"When called, requests that the Node.js event loop _not_ exit so long as the `Timeout` is active. Calling `timeout.ref()` multiple times will have no effect.","examples":[],"children":[]},{"kind":"method","id":"timeoutrefresh","name":"refresh","title":"`timeout.refresh()`","scope":"module","overloadOf":null,"stability":null,"added":["v10.2.0"],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"signature":{"parameters":[],"returns":{"type":{"text":"Timeout","links":[{"name":"Timeout","href":"timers.html#class-timeout","start":0,"end":7}]},"description":"a reference to `timeout`"}},"description":"Sets the timer's start time to the current time, and reschedules the timer to\ncall its callback at the previously specified duration adjusted to the current\ntime. This is useful for refreshing a timer without allocating a new\nJavaScript object.\n\nUsing this on a timer that has already called its callback will reactivate the\ntimer.","summary":"Sets the timer's start time to the current time, and reschedules the timer to call its callback at the previously specified duration adjusted to the current time. This is useful for refreshing a timer without allocating a new JavaScript object.","examples":[],"children":[]},{"kind":"method","id":"timeoutunref","name":"unref","title":"`timeout.unref()`","scope":"module","overloadOf":null,"stability":null,"added":["v0.9.1"],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"signature":{"parameters":[],"returns":{"type":{"text":"Timeout","links":[{"name":"Timeout","href":"timers.html#class-timeout","start":0,"end":7}]},"description":"a reference to `timeout`"}},"description":"When called, the active `Timeout` object will not require the Node.js event loop\nto remain active. If there is no other activity keeping the event loop running,\nthe process may exit before the `Timeout` object's callback is invoked. Calling\n`timeout.unref()` multiple times will have no effect.","summary":"When called, the active `Timeout` object will not require the Node.js event loop to remain active. If there is no other activity keeping the event loop running, the process may exit before the `Timeout` object's callback is invoked. Calling `timeout.unref()` multiple times will have no effect.","examples":[],"children":[]},{"kind":"method","id":"timeoutsymboltoprimitive","name":"[Symbol.toPrimitive]","title":"`timeout[Symbol.toPrimitive]()`","scope":"module","overloadOf":null,"stability":null,"added":["v14.9.0","v12.19.0"],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"signature":{"parameters":[],"returns":{"type":{"text":"integer","links":[{"name":"integer","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#number_type","start":0,"end":7}]},"description":"a number that can be used to reference this `timeout`"}},"description":"Coerce a `Timeout` to a primitive. The primitive can be used to\nclear the `Timeout`. The primitive can only be used in the\nsame thread where the timeout was created. Therefore, to use it\nacross [`worker_threads`](worker_threads.html) it must first be passed to the correct\nthread. This allows enhanced compatibility with browser\n`setTimeout()` and `setInterval()` implementations.","summary":"Coerce a `Timeout` to a primitive. The primitive can be used to clear the `Timeout`. The primitive can only be used in the same thread where the timeout was created. Therefore, to use it across `worker_threads` it must first be passed to the correct thread. This allows enhanced compatibility with browser `setTimeout()` and `setInterval()` implementations.","examples":[],"children":[]},{"kind":"method","id":"timeoutsymboldispose","name":"[Symbol.dispose]","title":"`timeout[Symbol.dispose]()`","scope":"module","overloadOf":null,"stability":null,"added":["v20.5.0","v18.18.0"],"deprecated":[],"removed":[],"napiVersion":[],"changes":[{"versions":["v24.2.0"],"prUrl":"https://github.com/nodejs/node/pull/58467","commit":null,"description":"No longer experimental."}],"signature":{"parameters":[],"returns":null},"description":"Cancels the timeout.","summary":"Cancels the timeout.","examples":[],"children":[]}]},{"kind":"section","id":"scheduling-timers","name":"Scheduling timers","title":"Scheduling timers","scope":"module","overloadOf":null,"stability":null,"added":[],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"description":"A timer in Node.js is an internal construct that calls a given function after\na certain period of time. When a timer's function is called varies depending on\nwhich method was used to create the timer and what other work the Node.js\nevent loop is doing.","summary":"A timer in Node.js is an internal construct that calls a given function after a certain period of time. When a timer's function is called varies depending on which method was used to create the timer and what other work the Node.js event loop is doing.","examples":[],"children":[{"kind":"method","id":"setimmediatecallback-args","name":"setImmediate","title":"`setImmediate(callback[, ...args])`","scope":"module","overloadOf":null,"stability":null,"added":["v0.9.1"],"deprecated":[],"removed":[],"napiVersion":[],"changes":[{"versions":["v18.0.0"],"prUrl":"https://github.com/nodejs/node/pull/41678","commit":null,"description":"Passing an invalid callback to the `callback` argument now throws `ERR_INVALID_ARG_TYPE` instead of `ERR_INVALID_CALLBACK`."}],"signature":{"parameters":[{"name":"callback","type":{"text":"Function","links":[{"name":"Function","href":"https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Function","start":0,"end":8}]},"description":"The function to call at the end of this turn of\nthe Node.js [Event Loop](https://nodejs.org/learn/asynchronous-work/event-loop-timers-and-nexttick#setimmediate-vs-settimeout)","default":null,"optional":false,"rest":false,"properties":[]},{"name":"args","type":{"text":"any","links":[{"name":"any","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Data_types","start":0,"end":3}]},"description":"Optional arguments to pass when the `callback` is called.","default":null,"optional":true,"rest":true,"properties":[]}],"returns":{"type":{"text":"Immediate","links":[{"name":"Immediate","href":"timers.html#class-immediate","start":0,"end":9}]},"description":"for use with [`clearImmediate()`](#clearimmediateimmediate)"}},"description":"Schedules the \"immediate\" execution of the `callback` after I/O events'\ncallbacks.\n\nWhen multiple calls to `setImmediate()` are made, the `callback` functions are\nqueued for execution in the order in which they are created. The entire callback\nqueue is processed every event loop iteration. If an immediate timer is queued\nfrom inside an executing callback, that timer will not be triggered until the\nnext event loop iteration.\n\nIf `callback` is not a function, a [`TypeError`](errors.html#class-typeerror) will be thrown.\n\nThis method has a custom variant for promises that is available using\n[`timersPromises.setImmediate()`](#timerspromisessetimmediatevalue-options).","summary":"Schedules the \"immediate\" execution of the `callback` after I/O events' callbacks.","examples":[],"children":[]},{"kind":"method","id":"setintervalcallback-delay-args","name":"setInterval","title":"`setInterval(callback[, delay[, ...args]])`","scope":"module","overloadOf":null,"stability":null,"added":["v0.0.1"],"deprecated":[],"removed":[],"napiVersion":[],"changes":[{"versions":["v18.0.0"],"prUrl":"https://github.com/nodejs/node/pull/41678","commit":null,"description":"Passing an invalid callback to the `callback` argument now throws `ERR_INVALID_ARG_TYPE` instead of `ERR_INVALID_CALLBACK`."}],"signature":{"parameters":[{"name":"callback","type":{"text":"Function","links":[{"name":"Function","href":"https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Function","start":0,"end":8}]},"description":"The function to call when the timer elapses.","default":null,"optional":false,"rest":false,"properties":[]},{"name":"delay","type":{"text":"number","links":[{"name":"number","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#number_type","start":0,"end":6}]},"description":"The number of milliseconds to wait before calling the\n`callback`.","default":"1","optional":true,"rest":false,"properties":[]},{"name":"args","type":{"text":"any","links":[{"name":"any","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Data_types","start":0,"end":3}]},"description":"Optional arguments to pass when the `callback` is called.","default":null,"optional":true,"rest":true,"properties":[]}],"returns":{"type":{"text":"Timeout","links":[{"name":"Timeout","href":"timers.html#class-timeout","start":0,"end":7}]},"description":"for use with [`clearInterval()`](#clearintervaltimeout)"}},"description":"Schedules repeated execution of `callback` every `delay` milliseconds.\n\nWhen `delay` is larger than `2147483647` or less than `1` or `NaN`, the `delay`\nwill be set to `1`. Non-integer delays are truncated to an integer.\n\nIf `callback` is not a function, a [`TypeError`](errors.html#class-typeerror) will be thrown.\n\nThis method has a custom variant for promises that is available using\n[`timersPromises.setInterval()`](#timerspromisessetintervaldelay-value-options).","summary":"Schedules repeated execution of `callback` every `delay` milliseconds.","examples":[],"children":[]},{"kind":"method","id":"settimeoutcallback-delay-args","name":"setTimeout","title":"`setTimeout(callback[, delay[, ...args]])`","scope":"module","overloadOf":null,"stability":null,"added":["v0.0.1"],"deprecated":[],"removed":[],"napiVersion":[],"changes":[{"versions":["v18.0.0"],"prUrl":"https://github.com/nodejs/node/pull/41678","commit":null,"description":"Passing an invalid callback to the `callback` argument now throws `ERR_INVALID_ARG_TYPE` instead of `ERR_INVALID_CALLBACK`."}],"signature":{"parameters":[{"name":"callback","type":{"text":"Function","links":[{"name":"Function","href":"https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Function","start":0,"end":8}]},"description":"The function to call when the timer elapses.","default":null,"optional":false,"rest":false,"properties":[]},{"name":"delay","type":{"text":"number","links":[{"name":"number","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#number_type","start":0,"end":6}]},"description":"The number of milliseconds to wait before calling the\n`callback`.","default":"1","optional":true,"rest":false,"properties":[]},{"name":"args","type":{"text":"any","links":[{"name":"any","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Data_types","start":0,"end":3}]},"description":"Optional arguments to pass when the `callback` is called.","default":null,"optional":true,"rest":true,"properties":[]}],"returns":{"type":{"text":"Timeout","links":[{"name":"Timeout","href":"timers.html#class-timeout","start":0,"end":7}]},"description":"for use with [`clearTimeout()`](#cleartimeouttimeout)"}},"description":"Schedules execution of a one-time `callback` after `delay` milliseconds.\n\nThe `callback` will likely not be invoked in precisely `delay` milliseconds.\nNode.js makes no guarantees about the exact timing of when callbacks will fire,\nnor of their ordering. The callback will be called as close as possible to the\ntime specified.\n\nWhen `delay` is larger than `2147483647` or less than `1` or `NaN`, the `delay`\nwill be set to `1`. Non-integer delays are truncated to an integer.\n\nIf `callback` is not a function, a [`TypeError`](errors.html#class-typeerror) will be thrown.\n\nThis method has a custom variant for promises that is available using\n[`timersPromises.setTimeout()`](#timerspromisessettimeoutdelay-value-options).","summary":"Schedules execution of a one-time `callback` after `delay` milliseconds.","examples":[],"children":[]}]},{"kind":"section","id":"cancelling-timers","name":"Cancelling timers","title":"Cancelling timers","scope":"module","overloadOf":null,"stability":null,"added":[],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"description":"The [`setImmediate()`](#setimmediatecallback-args), [`setInterval()`](#setintervalcallback-delay-args), and [`setTimeout()`](#settimeoutcallback-delay-args) methods\neach return objects that represent the scheduled timers. These can be used to\ncancel the timer and prevent it from triggering.\n\nFor the promisified variants of [`setImmediate()`](#setimmediatecallback-args) and [`setTimeout()`](#settimeoutcallback-delay-args),\nan [`AbortController`](globals.html#class-abortcontroller) may be used to cancel the timer. When canceled, the\nreturned Promises will be rejected with an `'AbortError'`.\n\nFor `setImmediate()`:\n\n```mjs\nimport { setImmediate as setImmediatePromise } from 'node:timers/promises';\n\nconst ac = new AbortController();\nconst signal = ac.signal;\n\n// We do not `await` the promise so `ac.abort()` is called concurrently.\nsetImmediatePromise('foobar', { signal })\n  .then(console.log)\n  .catch((err) => {\n    if (err.name === 'AbortError')\n      console.error('The immediate was aborted');\n  });\n\nac.abort();\n```\n\n```cjs\nconst { setImmediate: setImmediatePromise } = require('node:timers/promises');\n\nconst ac = new AbortController();\nconst signal = ac.signal;\n\nsetImmediatePromise('foobar', { signal })\n  .then(console.log)\n  .catch((err) => {\n    if (err.name === 'AbortError')\n      console.error('The immediate was aborted');\n  });\n\nac.abort();\n```\n\nFor `setTimeout()`:\n\n```mjs\nimport { setTimeout as setTimeoutPromise } from 'node:timers/promises';\n\nconst ac = new AbortController();\nconst signal = ac.signal;\n\n// We do not `await` the promise so `ac.abort()` is called concurrently.\nsetTimeoutPromise(1000, 'foobar', { signal })\n  .then(console.log)\n  .catch((err) => {\n    if (err.name === 'AbortError')\n      console.error('The timeout was aborted');\n  });\n\nac.abort();\n```\n\n```cjs\nconst { setTimeout: setTimeoutPromise } = require('node:timers/promises');\n\nconst ac = new AbortController();\nconst signal = ac.signal;\n\nsetTimeoutPromise(1000, 'foobar', { signal })\n  .then(console.log)\n  .catch((err) => {\n    if (err.name === 'AbortError')\n      console.error('The timeout was aborted');\n  });\n\nac.abort();\n```","summary":"The `setImmediate()`, `setInterval()`, and `setTimeout()` methods each return objects that represent the scheduled timers. These can be used to cancel the timer and prevent it from triggering.","examples":[{"language":"mjs","displayName":null,"code":"import { setImmediate as setImmediatePromise } from 'node:timers/promises';\n\nconst ac = new AbortController();\nconst signal = ac.signal;\n\n// We do not `await` the promise so `ac.abort()` is called concurrently.\nsetImmediatePromise('foobar', { signal })\n  .then(console.log)\n  .catch((err) => {\n    if (err.name === 'AbortError')\n      console.error('The immediate was aborted');\n  });\n\nac.abort();"},{"language":"cjs","displayName":null,"code":"const { setImmediate: setImmediatePromise } = require('node:timers/promises');\n\nconst ac = new AbortController();\nconst signal = ac.signal;\n\nsetImmediatePromise('foobar', { signal })\n  .then(console.log)\n  .catch((err) => {\n    if (err.name === 'AbortError')\n      console.error('The immediate was aborted');\n  });\n\nac.abort();"},{"language":"mjs","displayName":null,"code":"import { setTimeout as setTimeoutPromise } from 'node:timers/promises';\n\nconst ac = new AbortController();\nconst signal = ac.signal;\n\n// We do not `await` the promise so `ac.abort()` is called concurrently.\nsetTimeoutPromise(1000, 'foobar', { signal })\n  .then(console.log)\n  .catch((err) => {\n    if (err.name === 'AbortError')\n      console.error('The timeout was aborted');\n  });\n\nac.abort();"},{"language":"cjs","displayName":null,"code":"const { setTimeout: setTimeoutPromise } = require('node:timers/promises');\n\nconst ac = new AbortController();\nconst signal = ac.signal;\n\nsetTimeoutPromise(1000, 'foobar', { signal })\n  .then(console.log)\n  .catch((err) => {\n    if (err.name === 'AbortError')\n      console.error('The timeout was aborted');\n  });\n\nac.abort();"}],"children":[{"kind":"method","id":"clearimmediateimmediate","name":"clearImmediate","title":"`clearImmediate(immediate)`","scope":"module","overloadOf":null,"stability":null,"added":["v0.9.1"],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"signature":{"parameters":[{"name":"immediate","type":{"text":"Immediate","links":[{"name":"Immediate","href":"timers.html#class-immediate","start":0,"end":9}]},"description":"An `Immediate` object as returned by\n[`setImmediate()`](#setimmediatecallback-args).","default":null,"optional":false,"rest":false,"properties":[]}],"returns":null},"description":"Cancels an `Immediate` object created by [`setImmediate()`](#setimmediatecallback-args).","summary":"Cancels an `Immediate` object created by `setImmediate()`.","examples":[],"children":[]},{"kind":"method","id":"clearintervaltimeout","name":"clearInterval","title":"`clearInterval(timeout)`","scope":"module","overloadOf":null,"stability":null,"added":["v0.0.1"],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"signature":{"parameters":[{"name":"timeout","type":{"text":"Timeout | string | number","links":[{"name":"Timeout","href":"timers.html#class-timeout","start":0,"end":7},{"name":"string","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#string_type","start":10,"end":16},{"name":"number","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#number_type","start":19,"end":25}]},"description":"A `Timeout` object as returned by [`setInterval()`](#setintervalcallback-delay-args)\nor the [primitive](#timeoutsymboltoprimitive) of the `Timeout` object as a string or a number.","default":null,"optional":false,"rest":false,"properties":[]}],"returns":null},"description":"Cancels a `Timeout` object created by [`setInterval()`](#setintervalcallback-delay-args).","summary":"Cancels a `Timeout` object created by `setInterval()`.","examples":[],"children":[]},{"kind":"method","id":"cleartimeouttimeout","name":"clearTimeout","title":"`clearTimeout(timeout)`","scope":"module","overloadOf":null,"stability":null,"added":["v0.0.1"],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"signature":{"parameters":[{"name":"timeout","type":{"text":"Timeout | string | number","links":[{"name":"Timeout","href":"timers.html#class-timeout","start":0,"end":7},{"name":"string","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#string_type","start":10,"end":16},{"name":"number","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#number_type","start":19,"end":25}]},"description":"A `Timeout` object as returned by [`setTimeout()`](#settimeoutcallback-delay-args)\nor the [primitive](#timeoutsymboltoprimitive) of the `Timeout` object as a string or a number.","default":null,"optional":false,"rest":false,"properties":[]}],"returns":null},"description":"Cancels a `Timeout` object created by [`setTimeout()`](#settimeoutcallback-delay-args).","summary":"Cancels a `Timeout` object created by `setTimeout()`.","examples":[],"children":[]}]},{"kind":"section","id":"timers-promises-api","name":"Timers Promises API","title":"Timers Promises API","scope":"module","overloadOf":null,"stability":null,"added":["v15.0.0"],"deprecated":[],"removed":[],"napiVersion":[],"changes":[{"versions":["v16.0.0"],"prUrl":"https://github.com/nodejs/node/pull/38112","commit":null,"description":"Graduated from experimental."}],"description":"The `timers/promises` API provides an alternative set of timer functions\nthat return `Promise` objects. The API is accessible via\n`require('node:timers/promises')`.\n\n```mjs\nimport {\n  setTimeout,\n  setImmediate,\n  setInterval,\n} from 'node:timers/promises';\n```\n\n```cjs\nconst {\n  setTimeout,\n  setImmediate,\n  setInterval,\n} = require('node:timers/promises');\n```","summary":"The `timers/promises` API provides an alternative set of timer functions that return `Promise` objects. The API is accessible via `require('node:timers/promises')`.","examples":[{"language":"mjs","displayName":null,"code":"import {\n  setTimeout,\n  setImmediate,\n  setInterval,\n} from 'node:timers/promises';"},{"language":"cjs","displayName":null,"code":"const {\n  setTimeout,\n  setImmediate,\n  setInterval,\n} = require('node:timers/promises');"}],"children":[{"kind":"method","id":"timerspromisessettimeoutdelay-value-options","name":"setTimeout","title":"`timersPromises.setTimeout([delay[, value[, options]]])`","scope":"module","overloadOf":null,"stability":null,"added":["v15.0.0"],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"signature":{"parameters":[{"name":"delay","type":{"text":"number","links":[{"name":"number","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#number_type","start":0,"end":6}]},"description":"The number of milliseconds to wait before fulfilling the\npromise.","default":"1","optional":true,"rest":false,"properties":[]},{"name":"value","type":{"text":"any","links":[{"name":"any","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Data_types","start":0,"end":3}]},"description":"A value with which the promise is fulfilled.","default":null,"optional":true,"rest":false,"properties":[]},{"name":"options","type":{"text":"Object","links":[{"name":"Object","href":"https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object","start":0,"end":6}]},"description":"","default":null,"optional":true,"rest":false,"properties":[{"name":"ref","type":{"text":"boolean","links":[{"name":"boolean","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#boolean_type","start":0,"end":7}]},"description":"Set to `false` to indicate that the scheduled `Timeout`\nshould not require the Node.js event loop to remain active.","default":"true","optional":true,"rest":false,"properties":[]},{"name":"signal","type":{"text":"AbortSignal","links":[{"name":"AbortSignal","href":"globals.html#class-abortsignal","start":0,"end":11}]},"description":"An optional `AbortSignal` that can be used to\ncancel the scheduled `Timeout`.","default":null,"optional":false,"rest":false,"properties":[]}]}],"returns":null},"description":"```mjs\nimport {\n  setTimeout,\n} from 'node:timers/promises';\n\nconst res = await setTimeout(100, 'result');\n\nconsole.log(res);  // Prints 'result'\n```\n\n```cjs\nconst {\n  setTimeout,\n} = require('node:timers/promises');\n\nsetTimeout(100, 'result').then((res) => {\n  console.log(res);  // Prints 'result'\n});\n```","summary":"","examples":[{"language":"mjs","displayName":null,"code":"import {\n  setTimeout,\n} from 'node:timers/promises';\n\nconst res = await setTimeout(100, 'result');\n\nconsole.log(res);  // Prints 'result'"},{"language":"cjs","displayName":null,"code":"const {\n  setTimeout,\n} = require('node:timers/promises');\n\nsetTimeout(100, 'result').then((res) => {\n  console.log(res);  // Prints 'result'\n});"}],"children":[]},{"kind":"method","id":"timerspromisessetimmediatevalue-options","name":"setImmediate","title":"`timersPromises.setImmediate([value[, options]])`","scope":"module","overloadOf":null,"stability":null,"added":["v15.0.0"],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"signature":{"parameters":[{"name":"value","type":{"text":"any","links":[{"name":"any","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Data_types","start":0,"end":3}]},"description":"A value with which the promise is fulfilled.","default":null,"optional":true,"rest":false,"properties":[]},{"name":"options","type":{"text":"Object","links":[{"name":"Object","href":"https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object","start":0,"end":6}]},"description":"","default":null,"optional":true,"rest":false,"properties":[{"name":"ref","type":{"text":"boolean","links":[{"name":"boolean","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#boolean_type","start":0,"end":7}]},"description":"Set to `false` to indicate that the scheduled `Immediate`\nshould not require the Node.js event loop to remain active.","default":"true","optional":true,"rest":false,"properties":[]},{"name":"signal","type":{"text":"AbortSignal","links":[{"name":"AbortSignal","href":"globals.html#class-abortsignal","start":0,"end":11}]},"description":"An optional `AbortSignal` that can be used to\ncancel the scheduled `Immediate`.","default":null,"optional":false,"rest":false,"properties":[]}]}],"returns":null},"description":"```mjs\nimport {\n  setImmediate,\n} from 'node:timers/promises';\n\nconst res = await setImmediate('result');\n\nconsole.log(res);  // Prints 'result'\n```\n\n```cjs\nconst {\n  setImmediate,\n} = require('node:timers/promises');\n\nsetImmediate('result').then((res) => {\n  console.log(res);  // Prints 'result'\n});\n```","summary":"","examples":[{"language":"mjs","displayName":null,"code":"import {\n  setImmediate,\n} from 'node:timers/promises';\n\nconst res = await setImmediate('result');\n\nconsole.log(res);  // Prints 'result'"},{"language":"cjs","displayName":null,"code":"const {\n  setImmediate,\n} = require('node:timers/promises');\n\nsetImmediate('result').then((res) => {\n  console.log(res);  // Prints 'result'\n});"}],"children":[]},{"kind":"method","id":"timerspromisessetintervaldelay-value-options","name":"setInterval","title":"`timersPromises.setInterval([delay[, value[, options]]])`","scope":"module","overloadOf":null,"stability":null,"added":["v15.9.0"],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"signature":{"parameters":[{"name":"delay","type":{"text":"number","links":[{"name":"number","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#number_type","start":0,"end":6}]},"description":"The number of milliseconds to wait between iterations.","default":"1","optional":true,"rest":false,"properties":[]},{"name":"value","type":{"text":"any","links":[{"name":"any","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Data_types","start":0,"end":3}]},"description":"A value with which the iterator returns.","default":null,"optional":true,"rest":false,"properties":[]},{"name":"options","type":{"text":"Object","links":[{"name":"Object","href":"https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object","start":0,"end":6}]},"description":"","default":null,"optional":true,"rest":false,"properties":[{"name":"ref","type":{"text":"boolean","links":[{"name":"boolean","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#boolean_type","start":0,"end":7}]},"description":"Set to `false` to indicate that the scheduled `Timeout`\nbetween iterations should not require the Node.js event loop to\nremain active.","default":"true","optional":true,"rest":false,"properties":[]},{"name":"signal","type":{"text":"AbortSignal","links":[{"name":"AbortSignal","href":"globals.html#class-abortsignal","start":0,"end":11}]},"description":"An optional `AbortSignal` that can be used to\ncancel the scheduled `Timeout` between operations.","default":null,"optional":false,"rest":false,"properties":[]}]}],"returns":null},"description":"Returns an async iterator that generates values in an interval of `delay` ms.\nIf `ref` is `true`, you need to call `next()` of async iterator explicitly\nor implicitly to keep the event loop alive.\n\n```mjs\nimport {\n  setInterval,\n} from 'node:timers/promises';\n\nconst interval = 100;\nfor await (const startTime of setInterval(interval, Date.now())) {\n  const now = Date.now();\n  console.log(now);\n  if ((now - startTime) > 1000)\n    break;\n}\nconsole.log(Date.now());\n```\n\n```cjs\nconst {\n  setInterval,\n} = require('node:timers/promises');\nconst interval = 100;\n\n(async function() {\n  for await (const startTime of setInterval(interval, Date.now())) {\n    const now = Date.now();\n    console.log(now);\n    if ((now - startTime) > 1000)\n      break;\n  }\n  console.log(Date.now());\n})();\n```","summary":"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.","examples":[{"language":"mjs","displayName":null,"code":"import {\n  setInterval,\n} from 'node:timers/promises';\n\nconst interval = 100;\nfor await (const startTime of setInterval(interval, Date.now())) {\n  const now = Date.now();\n  console.log(now);\n  if ((now - startTime) > 1000)\n    break;\n}\nconsole.log(Date.now());"},{"language":"cjs","displayName":null,"code":"const {\n  setInterval,\n} = require('node:timers/promises');\nconst interval = 100;\n\n(async function() {\n  for await (const startTime of setInterval(interval, Date.now())) {\n    const now = Date.now();\n    console.log(now);\n    if ((now - startTime) > 1000)\n      break;\n  }\n  console.log(Date.now());\n})();"}],"children":[]},{"kind":"method","id":"timerspromisesschedulerwaitdelay-options","name":"wait","title":"`timersPromises.scheduler.wait(delay[, options])`","scope":"module","overloadOf":null,"stability":{"index":"1","description":"Experimental"},"added":["v17.3.0","v16.14.0"],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"signature":{"parameters":[{"name":"delay","type":{"text":"number","links":[{"name":"number","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#number_type","start":0,"end":6}]},"description":"The number of milliseconds to wait before resolving the\npromise.","default":null,"optional":false,"rest":false,"properties":[]},{"name":"options","type":{"text":"Object","links":[{"name":"Object","href":"https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object","start":0,"end":6}]},"description":"","default":null,"optional":true,"rest":false,"properties":[{"name":"ref","type":{"text":"boolean","links":[{"name":"boolean","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#boolean_type","start":0,"end":7}]},"description":"Set to `false` to indicate that the scheduled `Timeout`\nshould not require the Node.js event loop to remain active.","default":"true","optional":true,"rest":false,"properties":[]},{"name":"signal","type":{"text":"AbortSignal","links":[{"name":"AbortSignal","href":"globals.html#class-abortsignal","start":0,"end":11}]},"description":"An optional `AbortSignal` that can be used to\ncancel waiting.","default":null,"optional":false,"rest":false,"properties":[]}]}],"returns":{"type":{"text":"Promise","links":[{"name":"Promise","href":"https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise","start":0,"end":7}]},"description":""}},"description":"An experimental API defined by the [Scheduling APIs](https://github.com/WICG/scheduling-apis) draft specification\nbeing developed as a standard Web Platform API.\n\nCalling `timersPromises.scheduler.wait(delay, options)` is equivalent\nto calling `timersPromises.setTimeout(delay, undefined, options)`.\n\n```mjs\nimport { scheduler } from 'node:timers/promises';\n\nawait scheduler.wait(1000); // Wait one second before continuing\n```","summary":"An experimental API defined by the Scheduling APIs draft specification being developed as a standard Web Platform API.","examples":[{"language":"mjs","displayName":null,"code":"import { scheduler } from 'node:timers/promises';\n\nawait scheduler.wait(1000); // Wait one second before continuing"}],"children":[]},{"kind":"method","id":"timerspromisesscheduleryield","name":"yield","title":"`timersPromises.scheduler.yield()`","scope":"module","overloadOf":null,"stability":{"index":"1","description":"Experimental"},"added":["v17.3.0","v16.14.0"],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"signature":{"parameters":[],"returns":{"type":{"text":"Promise","links":[{"name":"Promise","href":"https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise","start":0,"end":7}]},"description":""}},"description":"An experimental API defined by the [Scheduling APIs](https://github.com/WICG/scheduling-apis) draft specification\nbeing developed as a standard Web Platform API.\n\nCalling `timersPromises.scheduler.yield()` is equivalent to calling\n`timersPromises.setImmediate()` with no arguments.","summary":"An experimental API defined by the Scheduling APIs draft specification being developed as a standard Web Platform API.","examples":[],"children":[]}]}]}