定时器


¥Timers

稳定性: 2 - 稳定的

¥Stability: 2 - Stable

源代码: lib/timers.js

timer 模块暴露了一个全局的用于在未来某个时间点调用的调度函数的 API。因为定时器函数是全局的,所以不需要调用 require('node:timers') 来使用该 API。

¥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.

Node.js 中的定时器函数实现了与 Web 浏览器提供的定时器 API 类似的 API,但使用了围绕 Node.js 事件循环 构建的不同内部实现。

¥The timer functions within Node.js implement a similar API as the timers API provided by Web Browsers but use a different internal implementation that is built around the Node.js Event Loop.