定时器的 Promise API
timers/promises
API 提供了一组可返回 Promise
对象的可供选择的定时器函数。
API 可通过 require('node:timers/promises')
访问。
import {
setTimeout,
setImmediate,
setInterval,
} from 'timers/promises';
const {
setTimeout,
setImmediate,
setInterval,
} = require('node:timers/promises');
The timers/promises
API provides an alternative set of timer functions
that return Promise
objects. The API is accessible via
require('node:timers/promises')
.
import {
setTimeout,
setImmediate,
setInterval,
} from 'timers/promises';
const {
setTimeout,
setImmediate,
setInterval,
} = require('node:timers/promises');