{
  "source": "doc/api/timers.md",
  "modules": [
    {
      "textRaw": "Timers",
      "name": "timers",
      "introduced_in": "v0.10.0",
      "stability": 2,
      "stabilityText": "Stable",
      "desc": "<p>The <code>timer</code> 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 <code>require(&#39;timers&#39;)</code> to use the API.</p>\n<p>The 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 <a href=\"https://nodejs.org/en/docs/guides/event-loop-timers-and-nexttick\">the Node.js Event Loop</a>.</p>\n",
      "classes": [
        {
          "textRaw": "Class: Immediate",
          "type": "class",
          "name": "Immediate",
          "desc": "<p>This object is created internally and is returned from <a href=\"timers.html#timers_setimmediate_callback_args\"><code>setImmediate()</code></a>. It\ncan be passed to <a href=\"timers.html#timers_clearimmediate_immediate\"><code>clearImmediate()</code></a> in order to cancel the scheduled\nactions.</p>\n"
        },
        {
          "textRaw": "Class: Timeout",
          "type": "class",
          "name": "Timeout",
          "desc": "<p>This object is created internally and is returned from <a href=\"timers.html#timers_settimeout_callback_delay_args\"><code>setTimeout()</code></a> and\n<a href=\"timers.html#timers_setinterval_callback_delay_args\"><code>setInterval()</code></a>. It can be passed to <a href=\"timers.html#timers_cleartimeout_timeout\"><code>clearTimeout()</code></a> or\n<a href=\"timers.html#timers_clearinterval_timeout\"><code>clearInterval()</code></a> (respectively) in order to cancel the scheduled actions.</p>\n<p>By default, when a timer is scheduled using either <a href=\"timers.html#timers_settimeout_callback_delay_args\"><code>setTimeout()</code></a> or\n<a href=\"timers.html#timers_setinterval_callback_delay_args\"><code>setInterval()</code></a>, the Node.js event loop will continue running as long as the\ntimer is active. Each of the <code>Timeout</code> objects returned by these functions\nexport both <code>timeout.ref()</code> and <code>timeout.unref()</code> functions that can be used to\ncontrol this default behavior.</p>\n",
          "methods": [
            {
              "textRaw": "timeout.ref()",
              "type": "method",
              "name": "ref",
              "meta": {
                "added": [
                  "v0.9.1"
                ]
              },
              "desc": "<p>When called, requests that the Node.js event loop <em>not</em> exit so long as the\n<code>Timeout</code> is active. Calling <code>timeout.ref()</code> multiple times will have no effect.</p>\n<p><em>Note</em>: By default, all <code>Timeout</code> objects are &quot;ref&#39;d&quot;, making it normally\nunnecessary to call <code>timeout.ref()</code> unless <code>timeout.unref()</code> had been called\npreviously.</p>\n<p>Returns a reference to the <code>Timeout</code>.</p>\n",
              "signatures": [
                {
                  "params": []
                }
              ]
            },
            {
              "textRaw": "timeout.unref()",
              "type": "method",
              "name": "unref",
              "meta": {
                "added": [
                  "v0.9.1"
                ]
              },
              "desc": "<p>When called, the active <code>Timeout</code> 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 <code>Timeout</code> object&#39;s callback is invoked. Calling\n<code>timeout.unref()</code> multiple times will have no effect.</p>\n<p><em>Note</em>: Calling <code>timeout.unref()</code> creates an internal timer that will wake the\nNode.js event loop. Creating too many of these can adversely impact performance\nof the Node.js application.</p>\n<p>Returns a reference to the <code>Timeout</code>.</p>\n",
              "signatures": [
                {
                  "params": []
                }
              ]
            }
          ]
        }
      ],
      "modules": [
        {
          "textRaw": "Scheduling Timers",
          "name": "scheduling_timers",
          "desc": "<p>A timer in Node.js is an internal construct that calls a given function after\na certain period of time. When a timer&#39;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.</p>\n",
          "methods": [
            {
              "textRaw": "setImmediate(callback[, ...args])",
              "type": "method",
              "name": "setImmediate",
              "meta": {
                "added": [
                  "v0.9.1"
                ]
              },
              "signatures": [
                {
                  "params": [
                    {
                      "textRaw": "`callback` {Function} The function to call at the end of this turn of [the Node.js Event Loop] ",
                      "name": "callback",
                      "type": "Function",
                      "desc": "The function to call at the end of this turn of [the Node.js Event Loop]"
                    },
                    {
                      "textRaw": "`...args` {any} Optional arguments to pass when the `callback` is called. ",
                      "name": "...args",
                      "type": "any",
                      "desc": "Optional arguments to pass when the `callback` is called.",
                      "optional": true
                    }
                  ]
                },
                {
                  "params": [
                    {
                      "name": "callback"
                    },
                    {
                      "name": "...args",
                      "optional": true
                    }
                  ]
                }
              ],
              "desc": "<p>Schedules the &quot;immediate&quot; execution of the <code>callback</code> after I/O events&#39;\ncallbacks and before timers created using <a href=\"timers.html#timers_settimeout_callback_delay_args\"><code>setTimeout()</code></a> and\n<a href=\"timers.html#timers_setinterval_callback_delay_args\"><code>setInterval()</code></a> are triggered. Returns an <code>Immediate</code> for use with\n<a href=\"timers.html#timers_clearimmediate_immediate\"><code>clearImmediate()</code></a>.</p>\n<p>When multiple calls to <code>setImmediate()</code> are made, the <code>callback</code> 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.</p>\n<p>If <code>callback</code> is not a function, a <a href=\"errors.html#errors_class_typeerror\"><code>TypeError</code></a> will be thrown.</p>\n"
            },
            {
              "textRaw": "setInterval(callback, delay[, ...args])",
              "type": "method",
              "name": "setInterval",
              "meta": {
                "added": [
                  "v0.0.1"
                ]
              },
              "signatures": [
                {
                  "params": [
                    {
                      "textRaw": "`callback` {Function} The function to call when the timer elapses. ",
                      "name": "callback",
                      "type": "Function",
                      "desc": "The function to call when the timer elapses."
                    },
                    {
                      "textRaw": "`delay` {number} The number of milliseconds to wait before calling the `callback`. ",
                      "name": "delay",
                      "type": "number",
                      "desc": "The number of milliseconds to wait before calling the `callback`."
                    },
                    {
                      "textRaw": "`...args` {any} Optional arguments to pass when the `callback` is called. ",
                      "name": "...args",
                      "type": "any",
                      "desc": "Optional arguments to pass when the `callback` is called.",
                      "optional": true
                    }
                  ]
                },
                {
                  "params": [
                    {
                      "name": "callback"
                    },
                    {
                      "name": "delay"
                    },
                    {
                      "name": "...args",
                      "optional": true
                    }
                  ]
                }
              ],
              "desc": "<p>Schedules repeated execution of <code>callback</code> every <code>delay</code> milliseconds.\nReturns a <code>Timeout</code> for use with <a href=\"timers.html#timers_clearinterval_timeout\"><code>clearInterval()</code></a>.</p>\n<p>When <code>delay</code> is larger than <code>2147483647</code> or less than <code>1</code>, the <code>delay</code> will be\nset to <code>1</code>.</p>\n<p>If <code>callback</code> is not a function, a <a href=\"errors.html#errors_class_typeerror\"><code>TypeError</code></a> will be thrown.</p>\n"
            },
            {
              "textRaw": "setTimeout(callback, delay[, ...args])",
              "type": "method",
              "name": "setTimeout",
              "meta": {
                "added": [
                  "v0.0.1"
                ]
              },
              "signatures": [
                {
                  "params": [
                    {
                      "textRaw": "`callback` {Function} The function to call when the timer elapses. ",
                      "name": "callback",
                      "type": "Function",
                      "desc": "The function to call when the timer elapses."
                    },
                    {
                      "textRaw": "`delay` {number} The number of milliseconds to wait before calling the `callback`. ",
                      "name": "delay",
                      "type": "number",
                      "desc": "The number of milliseconds to wait before calling the `callback`."
                    },
                    {
                      "textRaw": "`...args` {any} Optional arguments to pass when the `callback` is called. ",
                      "name": "...args",
                      "type": "any",
                      "desc": "Optional arguments to pass when the `callback` is called.",
                      "optional": true
                    }
                  ]
                },
                {
                  "params": [
                    {
                      "name": "callback"
                    },
                    {
                      "name": "delay"
                    },
                    {
                      "name": "...args",
                      "optional": true
                    }
                  ]
                }
              ],
              "desc": "<p>Schedules execution of a one-time <code>callback</code> after <code>delay</code> milliseconds.\nReturns a <code>Timeout</code> for use with <a href=\"timers.html#timers_cleartimeout_timeout\"><code>clearTimeout()</code></a>.</p>\n<p>The <code>callback</code> will likely not be invoked in precisely <code>delay</code> 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.</p>\n<p><em>Note</em>: When <code>delay</code> is larger than <code>2147483647</code> or less than <code>1</code>, the <code>delay</code>\nwill be set to <code>1</code>.</p>\n<p>If <code>callback</code> is not a function, a <a href=\"errors.html#errors_class_typeerror\"><code>TypeError</code></a> will be thrown.</p>\n"
            }
          ],
          "type": "module",
          "displayName": "Scheduling Timers"
        },
        {
          "textRaw": "Cancelling Timers",
          "name": "cancelling_timers",
          "desc": "<p>The <a href=\"timers.html#timers_setimmediate_callback_args\"><code>setImmediate()</code></a>, <a href=\"timers.html#timers_setinterval_callback_delay_args\"><code>setInterval()</code></a>, and <a href=\"timers.html#timers_settimeout_callback_delay_args\"><code>setTimeout()</code></a> methods\neach return objects that represent the scheduled timers. These can be used to\ncancel the timer and prevent it from triggering.</p>\n",
          "methods": [
            {
              "textRaw": "clearImmediate(immediate)",
              "type": "method",
              "name": "clearImmediate",
              "meta": {
                "added": [
                  "v0.9.1"
                ]
              },
              "signatures": [
                {
                  "params": [
                    {
                      "textRaw": "`immediate` {Immediate} An `Immediate` object as returned by [`setImmediate()`][]. ",
                      "name": "immediate",
                      "type": "Immediate",
                      "desc": "An `Immediate` object as returned by [`setImmediate()`][]."
                    }
                  ]
                },
                {
                  "params": [
                    {
                      "name": "immediate"
                    }
                  ]
                }
              ],
              "desc": "<p>Cancels an <code>Immediate</code> object created by <a href=\"timers.html#timers_setimmediate_callback_args\"><code>setImmediate()</code></a>.</p>\n"
            },
            {
              "textRaw": "clearInterval(timeout)",
              "type": "method",
              "name": "clearInterval",
              "meta": {
                "added": [
                  "v0.0.1"
                ]
              },
              "signatures": [
                {
                  "params": [
                    {
                      "textRaw": "`timeout` {Timeout} A `Timeout` object as returned by [`setInterval()`][]. ",
                      "name": "timeout",
                      "type": "Timeout",
                      "desc": "A `Timeout` object as returned by [`setInterval()`][]."
                    }
                  ]
                },
                {
                  "params": [
                    {
                      "name": "timeout"
                    }
                  ]
                }
              ],
              "desc": "<p>Cancels a <code>Timeout</code> object created by <a href=\"timers.html#timers_setinterval_callback_delay_args\"><code>setInterval()</code></a>.</p>\n"
            },
            {
              "textRaw": "clearTimeout(timeout)",
              "type": "method",
              "name": "clearTimeout",
              "meta": {
                "added": [
                  "v0.0.1"
                ]
              },
              "signatures": [
                {
                  "params": [
                    {
                      "textRaw": "`timeout` {Timeout} A `Timeout` object as returned by [`setTimeout()`][]. ",
                      "name": "timeout",
                      "type": "Timeout",
                      "desc": "A `Timeout` object as returned by [`setTimeout()`][]."
                    }
                  ]
                },
                {
                  "params": [
                    {
                      "name": "timeout"
                    }
                  ]
                }
              ],
              "desc": "<p>Cancels a <code>Timeout</code> object created by <a href=\"timers.html#timers_settimeout_callback_delay_args\"><code>setTimeout()</code></a>.</p>\n"
            }
          ],
          "type": "module",
          "displayName": "Cancelling Timers"
        }
      ],
      "type": "module",
      "displayName": "Timers"
    }
  ]
}
