Node.js v18.12.1 documentation


Table of contents

Timers#

Stability: 2 - Stable

Source Code: lib/timers.js

The timer module exposes a global API for scheduling functions to be called at some future period of time. timer模块公开了一个全局API,用于在将来某个时间段调用调度函数。Because the timer functions are globals, there is no need to call require('node:timers') to use the API.因为计时器函数是全局的,所以不需要调用require('node:timers')来使用API。

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.Node.js中的计时器函数实现了与Web浏览器提供的计时器API类似的API,但使用了围绕Node.js事件循环构建的不同内部实现。