定时器


【Timers】

源代码: lib/timers.js

timer 模块提供了一个全局 API,用于安排函数在未来的某个时间被调用。由于定时器函数是全局的,因此使用该 API 时无需调用 require('node:timers')

【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 类似的接口,但使用了不同的内部实现,该实现是围绕 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.】