2012-02-27 11:09:34 -08:00
|
|
|
# Timers
|
2010-10-28 23:18:16 +11:00
|
|
|
|
2017-01-22 19:16:21 -08:00
|
|
|
<!--introduced_in=v0.10.0-->
|
|
|
|
|
2017-02-27 07:32:23 -08:00
|
|
|
> Stability: 2 - Stable
|
2012-03-02 15:14:03 -08:00
|
|
|
|
2020-06-22 13:56:08 -04:00
|
|
|
<!-- source_link=lib/timers.js -->
|
|
|
|
|
2016-05-23 14:12:20 -07:00
|
|
|
The `timer` module exposes a global API for scheduling functions to
|
|
|
|
be called at some future period of time. Because the timer functions are
|
2022-04-20 10:23:41 +02:00
|
|
|
globals, there is no need to call `require('node:timers')` to use the API.
|
2012-02-27 11:09:34 -08:00
|
|
|
|
2016-05-23 14:12:20 -07:00
|
|
|
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
|
2019-01-21 12:08:35 -08:00
|
|
|
built around the Node.js [Event Loop][].
|
2010-10-28 23:18:16 +11:00
|
|
|
|
2019-12-24 15:11:21 -08:00
|
|
|
## Class: `Immediate`
|
2010-10-28 23:18:16 +11:00
|
|
|
|
2016-05-23 14:12:20 -07:00
|
|
|
This object is created internally and is returned from [`setImmediate()`][]. It
|
|
|
|
can be passed to [`clearImmediate()`][] in order to cancel the scheduled
|
|
|
|
actions.
|
2011-09-13 20:02:54 -07:00
|
|
|
|
2018-01-13 16:51:28 -05:00
|
|
|
By default, when an immediate is scheduled, the Node.js event loop will continue
|
|
|
|
running as long as the immediate is active. The `Immediate` object returned by
|
|
|
|
[`setImmediate()`][] exports both `immediate.ref()` and `immediate.unref()`
|
|
|
|
functions that can be used to control this default behavior.
|
|
|
|
|
2019-12-24 15:11:21 -08:00
|
|
|
### `immediate.hasRef()`
|
2021-10-10 21:55:04 -07:00
|
|
|
|
2018-05-23 02:01:53 +04:00
|
|
|
<!-- YAML
|
2018-10-02 16:01:19 -07:00
|
|
|
added: v11.0.0
|
2018-05-23 02:01:53 +04:00
|
|
|
-->
|
|
|
|
|
|
|
|
* Returns: {boolean}
|
|
|
|
|
|
|
|
If true, the `Immediate` object will keep the Node.js event loop active.
|
|
|
|
|
2019-12-24 15:11:21 -08:00
|
|
|
### `immediate.ref()`
|
2021-10-10 21:55:04 -07:00
|
|
|
|
2018-01-13 16:51:28 -05:00
|
|
|
<!-- YAML
|
2018-02-27 19:21:55 +01:00
|
|
|
added: v9.7.0
|
2018-01-13 16:51:28 -05:00
|
|
|
-->
|
|
|
|
|
2018-04-26 02:49:11 +03:00
|
|
|
* Returns: {Immediate} a reference to `immediate`
|
2018-04-11 21:07:14 +03:00
|
|
|
|
2021-10-10 21:55:04 -07:00
|
|
|
When called, requests that the Node.js event loop _not_ exit so long as the
|
2018-01-13 16:51:28 -05:00
|
|
|
`Immediate` is active. Calling `immediate.ref()` multiple times will have no
|
|
|
|
effect.
|
|
|
|
|
2018-04-09 19:30:22 +03:00
|
|
|
By default, all `Immediate` objects are "ref'ed", making it normally unnecessary
|
2018-02-05 21:55:16 -08:00
|
|
|
to call `immediate.ref()` unless `immediate.unref()` had been called previously.
|
2018-01-13 16:51:28 -05:00
|
|
|
|
2019-12-24 15:11:21 -08:00
|
|
|
### `immediate.unref()`
|
2021-10-10 21:55:04 -07:00
|
|
|
|
2018-01-13 16:51:28 -05:00
|
|
|
<!-- YAML
|
2018-02-27 19:21:55 +01:00
|
|
|
added: v9.7.0
|
2018-01-13 16:51:28 -05:00
|
|
|
-->
|
|
|
|
|
2018-04-26 02:49:11 +03:00
|
|
|
* Returns: {Immediate} a reference to `immediate`
|
2018-04-11 21:07:14 +03:00
|
|
|
|
2018-01-13 16:51:28 -05:00
|
|
|
When called, the active `Immediate` object will not require the Node.js event
|
|
|
|
loop to remain active. If there is no other activity keeping the event loop
|
|
|
|
running, the process may exit before the `Immediate` object's callback is
|
|
|
|
invoked. Calling `immediate.unref()` multiple times will have no effect.
|
|
|
|
|
2023-07-05 16:39:38 +03:00
|
|
|
### `immediate[Symbol.dispose]()`
|
|
|
|
|
|
|
|
<!-- YAML
|
2023-09-16 22:51:24 -04:00
|
|
|
added:
|
|
|
|
- v20.5.0
|
|
|
|
- v18.18.0
|
2023-07-05 16:39:38 +03:00
|
|
|
-->
|
|
|
|
|
|
|
|
> Stability: 1 - Experimental
|
|
|
|
|
|
|
|
Cancels the immediate. This is similar to calling `clearImmediate()`.
|
|
|
|
|
2019-12-24 15:11:21 -08:00
|
|
|
## Class: `Timeout`
|
2015-10-24 23:56:49 -02:00
|
|
|
|
2016-05-23 14:12:20 -07:00
|
|
|
This object is created internally and is returned from [`setTimeout()`][] and
|
2018-04-11 17:49:07 +02:00
|
|
|
[`setInterval()`][]. It can be passed to either [`clearTimeout()`][] or
|
|
|
|
[`clearInterval()`][] in order to cancel the scheduled actions.
|
2010-10-28 23:18:16 +11:00
|
|
|
|
2016-09-11 09:42:00 +08:00
|
|
|
By default, when a timer is scheduled using either [`setTimeout()`][] or
|
2016-05-23 14:12:20 -07:00
|
|
|
[`setInterval()`][], the Node.js event loop will continue running as long as the
|
|
|
|
timer is active. Each of the `Timeout` objects returned by these functions
|
|
|
|
export both `timeout.ref()` and `timeout.unref()` functions that can be used to
|
|
|
|
control this default behavior.
|
2010-10-28 23:18:16 +11:00
|
|
|
|
2021-09-08 13:00:04 +03:00
|
|
|
### `timeout.close()`
|
2021-10-10 21:55:04 -07:00
|
|
|
|
2021-09-08 13:00:04 +03:00
|
|
|
<!-- YAML
|
|
|
|
added: v0.9.1
|
|
|
|
-->
|
|
|
|
|
|
|
|
> Stability: 3 - Legacy: Use [`clearTimeout()`][] instead.
|
|
|
|
|
|
|
|
* Returns: {Timeout} a reference to `timeout`
|
|
|
|
|
|
|
|
Cancels the timeout.
|
|
|
|
|
2019-12-24 15:11:21 -08:00
|
|
|
### `timeout.hasRef()`
|
2021-10-10 21:55:04 -07:00
|
|
|
|
2018-05-23 02:01:53 +04:00
|
|
|
<!-- YAML
|
2018-10-02 16:01:19 -07:00
|
|
|
added: v11.0.0
|
2018-05-23 02:01:53 +04:00
|
|
|
-->
|
|
|
|
|
|
|
|
* Returns: {boolean}
|
|
|
|
|
|
|
|
If true, the `Timeout` object will keep the Node.js event loop active.
|
|
|
|
|
2019-12-24 15:11:21 -08:00
|
|
|
### `timeout.ref()`
|
2021-10-10 21:55:04 -07:00
|
|
|
|
2016-06-30 08:52:44 +02:00
|
|
|
<!-- YAML
|
|
|
|
added: v0.9.1
|
|
|
|
-->
|
2015-11-04 12:35:20 -05:00
|
|
|
|
2018-04-26 02:49:11 +03:00
|
|
|
* Returns: {Timeout} a reference to `timeout`
|
2018-04-11 21:07:14 +03:00
|
|
|
|
2021-10-10 21:55:04 -07:00
|
|
|
When called, requests that the Node.js event loop _not_ exit so long as the
|
2016-05-23 14:12:20 -07:00
|
|
|
`Timeout` is active. Calling `timeout.ref()` multiple times will have no effect.
|
2015-11-04 12:35:20 -05:00
|
|
|
|
2018-04-09 19:30:22 +03:00
|
|
|
By default, all `Timeout` objects are "ref'ed", making it normally unnecessary
|
2018-02-05 21:55:16 -08:00
|
|
|
to call `timeout.ref()` unless `timeout.unref()` had been called previously.
|
2015-11-04 12:35:20 -05:00
|
|
|
|
2019-12-24 15:11:21 -08:00
|
|
|
### `timeout.refresh()`
|
2021-10-10 21:55:04 -07:00
|
|
|
|
2018-04-25 12:45:34 -04:00
|
|
|
<!-- YAML
|
2018-05-14 20:01:36 +02:00
|
|
|
added: v10.2.0
|
2018-04-25 12:45:34 -04:00
|
|
|
-->
|
|
|
|
|
|
|
|
* Returns: {Timeout} a reference to `timeout`
|
|
|
|
|
|
|
|
Sets the timer's start time to the current time, and reschedules the timer to
|
|
|
|
call its callback at the previously specified duration adjusted to the current
|
|
|
|
time. This is useful for refreshing a timer without allocating a new
|
|
|
|
JavaScript object.
|
|
|
|
|
|
|
|
Using this on a timer that has already called its callback will reactivate the
|
|
|
|
timer.
|
|
|
|
|
2019-12-24 15:11:21 -08:00
|
|
|
### `timeout.unref()`
|
2021-10-10 21:55:04 -07:00
|
|
|
|
2016-06-30 08:52:44 +02:00
|
|
|
<!-- YAML
|
|
|
|
added: v0.9.1
|
|
|
|
-->
|
2015-11-04 12:35:20 -05:00
|
|
|
|
2018-04-26 02:49:11 +03:00
|
|
|
* Returns: {Timeout} a reference to `timeout`
|
2018-04-11 21:07:14 +03:00
|
|
|
|
2016-05-23 14:12:20 -07:00
|
|
|
When called, the active `Timeout` object will not require the Node.js event loop
|
|
|
|
to remain active. If there is no other activity keeping the event loop running,
|
|
|
|
the process may exit before the `Timeout` object's callback is invoked. Calling
|
2016-08-23 14:45:49 +08:00
|
|
|
`timeout.unref()` multiple times will have no effect.
|
2015-11-04 12:35:20 -05:00
|
|
|
|
2020-06-19 21:31:21 +03:00
|
|
|
### `timeout[Symbol.toPrimitive]()`
|
2021-10-10 21:55:04 -07:00
|
|
|
|
2020-06-19 21:31:21 +03:00
|
|
|
<!-- YAML
|
2020-09-28 10:54:13 -07:00
|
|
|
added:
|
|
|
|
- v14.9.0
|
|
|
|
- v12.19.0
|
2020-06-19 21:31:21 +03:00
|
|
|
-->
|
|
|
|
|
2020-09-14 21:49:48 -06:00
|
|
|
* Returns: {integer} a number that can be used to reference this `timeout`
|
|
|
|
|
|
|
|
Coerce a `Timeout` to a primitive. The primitive can be used to
|
|
|
|
clear the `Timeout`. The primitive can only be used in the
|
|
|
|
same thread where the timeout was created. Therefore, to use it
|
|
|
|
across [`worker_threads`][] it must first be passed to the correct
|
|
|
|
thread. This allows enhanced compatibility with browser
|
|
|
|
`setTimeout()` and `setInterval()` implementations.
|
2020-06-19 21:31:21 +03:00
|
|
|
|
2023-07-05 16:39:38 +03:00
|
|
|
### `timeout[Symbol.dispose]()`
|
|
|
|
|
|
|
|
<!-- YAML
|
2023-09-16 22:51:24 -04:00
|
|
|
added:
|
|
|
|
- v20.5.0
|
|
|
|
- v18.18.0
|
2023-07-05 16:39:38 +03:00
|
|
|
-->
|
|
|
|
|
|
|
|
> Stability: 1 - Experimental
|
|
|
|
|
|
|
|
Cancels the timeout.
|
|
|
|
|
2020-06-14 14:49:34 -07:00
|
|
|
## Scheduling timers
|
2016-05-23 14:12:20 -07:00
|
|
|
|
|
|
|
A timer in Node.js is an internal construct that calls a given function after
|
|
|
|
a certain period of time. When a timer's function is called varies depending on
|
|
|
|
which method was used to create the timer and what other work the Node.js
|
|
|
|
event loop is doing.
|
|
|
|
|
2019-12-24 15:11:21 -08:00
|
|
|
### `setImmediate(callback[, ...args])`
|
2021-10-10 21:55:04 -07:00
|
|
|
|
2016-06-30 08:52:44 +02:00
|
|
|
<!-- YAML
|
|
|
|
added: v0.9.1
|
2022-01-24 19:39:16 +03:30
|
|
|
changes:
|
2022-04-19, Version 18.0.0 (Current)
Notable Changes:
Deprecations and Removals:
- (SEMVER-MAJOR) fs: runtime deprecate string coercion in `fs.write`,
`fs.writeFileSync`
(Livia Medeiros) (https://github.com/nodejs/node/pull/42607)
- (SEMVER-MAJOR) dns: remove `dns.lookup` and `dnsPromises.lookup`
options type coercion
(Antoine du Hamel) (https://github.com/nodejs/node/pull/41431)
- (SEMVER-MAJOR) process: runtime deprecate multipleResolves
(Benjamin Gruenbaum) (https://github.com/nodejs/node/pull/41896)
- (SEMVER-MAJOR) stream: remove thenable support (Robert Nagy)
(https://github.com/nodejs/node/pull/40773)
- (SEMVER-MAJOR) tls: move tls.parseCertString to end-of-life
(Tobias Nießen) (https://github.com/nodejs/node/pull/41479)
fetch (experimental):
An experimental fetch API is available on the global scope by default.
The implementation is based upon https://undici.nodejs.org/#/,
an HTTP/1.1 client written for Node.js by contributors to the project.
Through this addition, the following globals are made available: `fetch`
, `FormData`, `Headers`, `Request`, `Response`.
Disable this API with the `--no-experimental-fetch` command-line flag.
Contributed by Michaël Zasso in https://github.com/nodejs/node/pull/41811.
HTTP Timeouts:
`server.headersTimeout`, which limits the amount of time the parser will
wait to receive the complete HTTP headers, is now set to `60000` (60
seconds) by default.
`server.requestTimeout`, which sets the timeout value in milliseconds
for receiving the entire request from the client, is now set to `300000`
(5 minutes) by default.
If these timeouts expire, the server responds with status 408 without
forwarding the request to the request listener and then closes the
connection.
Both timeouts must be set to a non-zero value to protect against
potential Denial-of-Service attacks in case the server is deployed
without a reverse proxy in front.
Contributed by Paolo Insogna in https://github.com/nodejs/node/pull/41263.
Test Runner module (experimental):
The `node:test` module facilitates the creation of JavaScript tests that
report results in TAP format. This module is only available under the
`node:` scheme.
Contributed by Colin Ihrig in https://github.com/nodejs/node/pull/42325.
Toolchain and Compiler Upgrades:
- Prebuilt binaries for Linux are now built on Red Hat Enterprise Linux
(RHEL) 8 and are compatible with Linux distributions based on glibc
2.28 or later, for example, Debian 10, RHEL 8, Ubuntu 20.04.
- Prebuilt binaries for macOS now require macOS 10.15 or later.
- For AIX the minimum supported architecture has been raised from Power
7 to Power 8.
Prebuilt binaries for 32-bit Windows will initially not be available due
to issues building the V8 dependency in Node.js. We hope to restore
32-bit Windows binaries for Node.js 18 with a future V8 update.
Node.js does not support running on operating systems that are no longer
supported by their vendor. For operating systems where their vendor has
planned to end support earlier than April 2025, such as Windows 8.1
(January 2023) and Windows Server 2012 R2 (October 2023), support for
Node.js 18 will end at the earlier date.
Full details about the supported toolchains and compilers are documented
in the Node.js `BUILDING.md` file.
Contributed by Richard Lau in https://github.com/nodejs/node/pull/42292,
https://github.com/nodejs/node/pull/42604 and https://github.com/nodejs/node/pull/42659
, and Michaël Zasso in https://github.com/nodejs/node/pull/42105 and
https://github.com/nodejs/node/pull/42666.
V8 10.1:
The V8 engine is updated to version 10.1, which is part of Chromium 101.
Compared to the version included in Node.js 17.9.0, the following new
features are included:
- The `findLast` and `findLastIndex` array methods.
- Improvements to the `Intl.Locale` API.
- The `Intl.supportedValuesOf` function.
- Improved performance of class fields and private class methods (the
initialization of them is now as fast as ordinary property stores).
The data format returned by the serialization API (`v8.serialize(value)`)
has changed, and cannot be deserialized by earlier versions of Node.js.
On the other hand, it is still possible to deserialize the previous
format, as the API is backwards-compatible.
Contributed by Michaël Zasso in https://github.com/nodejs/node/pull/42657.
Web Streams API (experimental):
Node.js now exposes the experimental implementation of the Web Streams
API on the global scope. This means the following APIs are now globally
available:
- `ReadableStream`, `ReadableStreamDefaultReader`,
`ReadableStreamBYOBReader`, `ReadableStreamBYOBRequest`,
`ReadableByteStreamController`, `ReadableStreamDefaultController`,
`TransformStream`, `TransformStreamDefaultController`, `WritableStream`,
`WritableStreamDefaultWriter`, `WritableStreamDefaultController`,
`ByteLengthQueuingStrategy`, `CountQueuingStrategy`, `TextEncoderStream`,
`TextDecoderStream`, `CompressionStream`, `DecompressionStream`.
Contributed James Snell in https://github.com/nodejs/node/pull/39062,
and Antoine du Hamel in https://github.com/nodejs/node/pull/42225.
Other Notable Changes:
- (SEMVER-MAJOR) buffer: expose Blob as a global
(James M Snell) (https://github.com/nodejs/node/pull/41270)
- (SEMVER-MAJOR) child\_process: improve argument validation
(Rich Trott) (https://github.com/nodejs/node/pull/41305)
- doc: add RafaelGSS to collaborators
(RafaelGSS) (https://github.com/nodejs/node/pull/42718)
- (SEMVER-MAJOR) http: make TCP noDelay enabled by default
(Paolo Insogna) (https://github.com/nodejs/node/pull/42163)
- (SEMVER-MAJOR) net: make `server.address()` return an integer for
`family`
(Antoine du Hamel) (https://github.com/nodejs/node/pull/41431)
- (SEMVER-MAJOR) worker: expose BroadcastChannel as a global
(James M Snell) (https://github.com/nodejs/node/pull/41271)
- (SEMVER-MAJOR) worker: graduate BroadcastChannel to supported
(James M Snell) (https://github.com/nodejs/node/pull/41271)
Semver-Major Commits:
- (SEMVER-MAJOR) assert,util: compare RegExp.lastIndex while using deep
equal checks
(Ruben Bridgewater) (https://github.com/nodejs/node/pull/41020)
- (SEMVER-MAJOR) buffer: refactor `byteLength` to remove outdated
optimizations
(Rongjian Zhang) (https://github.com/nodejs/node/pull/38545)
- (SEMVER-MAJOR) buffer: expose Blob as a global
(James M Snell) (https://github.com/nodejs/node/pull/41270)
- (SEMVER-MAJOR) buffer: graduate Blob from experimental
(James M Snell) (https://github.com/nodejs/node/pull/41270)
- (SEMVER-MAJOR) build: make x86 Windows support temporarily
experimental
(Michaël Zasso) (https://github.com/nodejs/node/pull/42666)
- (SEMVER-MAJOR) build: bump macOS deployment target to 10.15
(Richard Lau) (https://github.com/nodejs/node/pull/42292)
- (SEMVER-MAJOR) build: downgrade Windows 8.1 and server 2012 R2 to
experimental
(Michaël Zasso) (https://github.com/nodejs/node/pull/42105)
- (SEMVER-MAJOR) child\_process: improve argument validation
(Rich Trott) (https://github.com/nodejs/node/pull/41305)
- (SEMVER-MAJOR) cluster: make `kill` to be just `process.kill`
(Bar Admoni) (https://github.com/nodejs/node/pull/34312)
- (SEMVER-MAJOR) crypto: cleanup validation
(Mohammed Keyvanzadeh) (https://github.com/nodejs/node/pull/39841)
- (SEMVER-MAJOR) crypto: prettify othername in PrintGeneralName
(Tobias Nießen) (https://github.com/nodejs/node/pull/42123)
- (SEMVER-MAJOR) crypto: fix X509Certificate toLegacyObject
(Tobias Nießen) (https://github.com/nodejs/node/pull/42124)
- (SEMVER-MAJOR) crypto: use RFC2253 format in PrintGeneralName
(Tobias Nießen) (https://github.com/nodejs/node/pull/42002)
- (SEMVER-MAJOR) crypto: change default check(Host|Email) behavior
(Tobias Nießen) (https://github.com/nodejs/node/pull/41600)
- (SEMVER-MAJOR) deps: V8: cherry-pick semver-major commits from 10.2
(Michaël Zasso) (https://github.com/nodejs/node/pull/42657)
- (SEMVER-MAJOR) deps: update V8 to 10.1.124.6
(Michaël Zasso) (https://github.com/nodejs/node/pull/42657)
- (SEMVER-MAJOR) deps: update V8 to 9.8.177.9
(Michaël Zasso) (https://github.com/nodejs/node/pull/41610)
- (SEMVER-MAJOR) deps: update V8 to 9.7.106.18
(Michaël Zasso) (https://github.com/nodejs/node/pull/40907)
- (SEMVER-MAJOR) dns: remove `dns.lookup` and `dnsPromises.lookup`
options type coercion
(Antoine du Hamel) (https://github.com/nodejs/node/pull/41431)
- (SEMVER-MAJOR) doc: update minimum glibc requirements for Linux
(Richard Lau) (https://github.com/nodejs/node/pull/42659)
- (SEMVER-MAJOR) doc: update AIX minimum supported arch
(Richard Lau) (https://github.com/nodejs/node/pull/42604)
- (SEMVER-MAJOR) fs: runtime deprecate string coercion in `fs.write`,
`fs.writeFileSync`
(Livia Medeiros) (https://github.com/nodejs/node/pull/42607)
- (SEMVER-MAJOR) http: refactor headersTimeout and requestTimeout logic
(Paolo Insogna) (https://github.com/nodejs/node/pull/41263)
- (SEMVER-MAJOR) http: make TCP noDelay enabled by default
(Paolo Insogna) (https://github.com/nodejs/node/pull/42163)
- (SEMVER-MAJOR) lib: enable fetch by default
(Michaël Zasso) (https://github.com/nodejs/node/pull/41811)
- (SEMVER-MAJOR) lib: replace validator and error
(Mohammed Keyvanzadeh) (https://github.com/nodejs/node/pull/41678)
- (SEMVER-MAJOR) module,repl: support 'node:'-only core modules
(Colin Ihrig) (https://github.com/nodejs/node/pull/42325)
- (SEMVER-MAJOR) net: make `server.address()` return an integer for
`family`
(Antoine du Hamel) (https://github.com/nodejs/node/pull/41431)
- (SEMVER-MAJOR) process: disallow some uses of Object.defineProperty()
on process.env
(Himself65) (https://github.com/nodejs/node/pull/28006)
- (SEMVER-MAJOR) process: runtime deprecate multipleResolves
(Benjamin Gruenbaum) (https://github.com/nodejs/node/pull/41896)
- (SEMVER-MAJOR) readline: fix question still called after closed
(Xuguang Mei) (https://github.com/nodejs/node/pull/42464)
- (SEMVER-MAJOR) stream: remove thenable support
(Robert Nagy) (https://github.com/nodejs/node/pull/40773)
- (SEMVER-MAJOR) stream: expose web streams globals, remove runtime
experimental warning
(Antoine du Hamel) (https://github.com/nodejs/node/pull/42225)
- (SEMVER-MAJOR) stream: need to cleanup event listeners if last stream
is readable
(Xuguang Mei) (https://github.com/nodejs/node/pull/41954)
- (SEMVER-MAJOR) stream: revert revert `map` spec compliance
(Benjamin Gruenbaum) (https://github.com/nodejs/node/pull/41933)
- (SEMVER-MAJOR) stream: throw invalid arg type from End Of Stream
(Jithil P Ponnan) (https://github.com/nodejs/node/pull/41766)
- (SEMVER-MAJOR) stream: don't emit finish after destroy
(Robert Nagy) (https://github.com/nodejs/node/pull/40852)
- (SEMVER-MAJOR) stream: add errored and closed props
(Robert Nagy) (https://github.com/nodejs/node/pull/40696)
- (SEMVER-MAJOR) test: add initial test module
(Colin Ihrig) (https://github.com/nodejs/node/pull/42325)
- (SEMVER-MAJOR) timers: refactor internal classes to ES2015 syntax
(Rabbit) (https://github.com/nodejs/node/pull/37408)
- (SEMVER-MAJOR) tls: represent registeredID numerically always
(Tobias Nießen) (https://github.com/nodejs/node/pull/41561)
- (SEMVER-MAJOR) tls: move tls.parseCertString to end-of-life
(Tobias Nießen) (https://github.com/nodejs/node/pull/41479)
- (SEMVER-MAJOR) url: throw on NULL in IPv6 hostname
(Rich Trott) (https://github.com/nodejs/node/pull/42313)
- (SEMVER-MAJOR) v8: make v8.writeHeapSnapshot() error codes consistent
(Darshan Sen) (https://github.com/nodejs/node/pull/42577)
- (SEMVER-MAJOR) v8: make writeHeapSnapshot throw if fopen fails
(Antonio Román) (https://github.com/nodejs/node/pull/41373)
- (SEMVER-MAJOR) worker: expose BroadcastChannel as a global
(James M Snell) (https://github.com/nodejs/node/pull/41271)
- (SEMVER-MAJOR) worker: graduate BroadcastChannel to supported
(James M Snell) (https://github.com/nodejs/node/pull/41271)
PR-URL: https://github.com/nodejs/node/pull/42262
2022-03-08 01:39:47 +00:00
|
|
|
- version: v18.0.0
|
2022-01-24 19:39:16 +03:30
|
|
|
pr-url: https://github.com/nodejs/node/pull/41678
|
|
|
|
description: Passing an invalid callback to the `callback` argument
|
|
|
|
now throws `ERR_INVALID_ARG_TYPE` instead of
|
|
|
|
`ERR_INVALID_CALLBACK`.
|
2016-06-30 08:52:44 +02:00
|
|
|
-->
|
2016-05-23 14:12:20 -07:00
|
|
|
|
|
|
|
* `callback` {Function} The function to call at the end of this turn of
|
2019-10-02 00:31:57 -04:00
|
|
|
the Node.js [Event Loop][]
|
2016-08-29 22:35:03 -07:00
|
|
|
* `...args` {any} Optional arguments to pass when the `callback` is called.
|
2018-04-26 02:49:11 +03:00
|
|
|
* Returns: {Immediate} for use with [`clearImmediate()`][]
|
2016-05-23 14:12:20 -07:00
|
|
|
|
|
|
|
Schedules the "immediate" execution of the `callback` after I/O events'
|
2018-04-26 02:49:11 +03:00
|
|
|
callbacks.
|
2016-05-23 14:12:20 -07:00
|
|
|
|
|
|
|
When multiple calls to `setImmediate()` are made, the `callback` functions are
|
|
|
|
queued for execution in the order in which they are created. The entire callback
|
|
|
|
queue is processed every event loop iteration. If an immediate timer is queued
|
|
|
|
from inside an executing callback, that timer will not be triggered until the
|
|
|
|
next event loop iteration.
|
|
|
|
|
|
|
|
If `callback` is not a function, a [`TypeError`][] will be thrown.
|
|
|
|
|
2018-02-05 21:55:16 -08:00
|
|
|
This method has a custom variant for promises that is available using
|
2021-06-26 16:03:02 -07:00
|
|
|
[`timersPromises.setImmediate()`][].
|
2017-04-14 21:42:47 +02:00
|
|
|
|
2020-10-23 00:12:44 +03:00
|
|
|
### `setInterval(callback[, delay[, ...args]])`
|
2021-10-10 21:55:04 -07:00
|
|
|
|
2016-06-30 08:52:44 +02:00
|
|
|
<!-- YAML
|
|
|
|
added: v0.0.1
|
2022-01-24 19:39:16 +03:30
|
|
|
changes:
|
2022-04-19, Version 18.0.0 (Current)
Notable Changes:
Deprecations and Removals:
- (SEMVER-MAJOR) fs: runtime deprecate string coercion in `fs.write`,
`fs.writeFileSync`
(Livia Medeiros) (https://github.com/nodejs/node/pull/42607)
- (SEMVER-MAJOR) dns: remove `dns.lookup` and `dnsPromises.lookup`
options type coercion
(Antoine du Hamel) (https://github.com/nodejs/node/pull/41431)
- (SEMVER-MAJOR) process: runtime deprecate multipleResolves
(Benjamin Gruenbaum) (https://github.com/nodejs/node/pull/41896)
- (SEMVER-MAJOR) stream: remove thenable support (Robert Nagy)
(https://github.com/nodejs/node/pull/40773)
- (SEMVER-MAJOR) tls: move tls.parseCertString to end-of-life
(Tobias Nießen) (https://github.com/nodejs/node/pull/41479)
fetch (experimental):
An experimental fetch API is available on the global scope by default.
The implementation is based upon https://undici.nodejs.org/#/,
an HTTP/1.1 client written for Node.js by contributors to the project.
Through this addition, the following globals are made available: `fetch`
, `FormData`, `Headers`, `Request`, `Response`.
Disable this API with the `--no-experimental-fetch` command-line flag.
Contributed by Michaël Zasso in https://github.com/nodejs/node/pull/41811.
HTTP Timeouts:
`server.headersTimeout`, which limits the amount of time the parser will
wait to receive the complete HTTP headers, is now set to `60000` (60
seconds) by default.
`server.requestTimeout`, which sets the timeout value in milliseconds
for receiving the entire request from the client, is now set to `300000`
(5 minutes) by default.
If these timeouts expire, the server responds with status 408 without
forwarding the request to the request listener and then closes the
connection.
Both timeouts must be set to a non-zero value to protect against
potential Denial-of-Service attacks in case the server is deployed
without a reverse proxy in front.
Contributed by Paolo Insogna in https://github.com/nodejs/node/pull/41263.
Test Runner module (experimental):
The `node:test` module facilitates the creation of JavaScript tests that
report results in TAP format. This module is only available under the
`node:` scheme.
Contributed by Colin Ihrig in https://github.com/nodejs/node/pull/42325.
Toolchain and Compiler Upgrades:
- Prebuilt binaries for Linux are now built on Red Hat Enterprise Linux
(RHEL) 8 and are compatible with Linux distributions based on glibc
2.28 or later, for example, Debian 10, RHEL 8, Ubuntu 20.04.
- Prebuilt binaries for macOS now require macOS 10.15 or later.
- For AIX the minimum supported architecture has been raised from Power
7 to Power 8.
Prebuilt binaries for 32-bit Windows will initially not be available due
to issues building the V8 dependency in Node.js. We hope to restore
32-bit Windows binaries for Node.js 18 with a future V8 update.
Node.js does not support running on operating systems that are no longer
supported by their vendor. For operating systems where their vendor has
planned to end support earlier than April 2025, such as Windows 8.1
(January 2023) and Windows Server 2012 R2 (October 2023), support for
Node.js 18 will end at the earlier date.
Full details about the supported toolchains and compilers are documented
in the Node.js `BUILDING.md` file.
Contributed by Richard Lau in https://github.com/nodejs/node/pull/42292,
https://github.com/nodejs/node/pull/42604 and https://github.com/nodejs/node/pull/42659
, and Michaël Zasso in https://github.com/nodejs/node/pull/42105 and
https://github.com/nodejs/node/pull/42666.
V8 10.1:
The V8 engine is updated to version 10.1, which is part of Chromium 101.
Compared to the version included in Node.js 17.9.0, the following new
features are included:
- The `findLast` and `findLastIndex` array methods.
- Improvements to the `Intl.Locale` API.
- The `Intl.supportedValuesOf` function.
- Improved performance of class fields and private class methods (the
initialization of them is now as fast as ordinary property stores).
The data format returned by the serialization API (`v8.serialize(value)`)
has changed, and cannot be deserialized by earlier versions of Node.js.
On the other hand, it is still possible to deserialize the previous
format, as the API is backwards-compatible.
Contributed by Michaël Zasso in https://github.com/nodejs/node/pull/42657.
Web Streams API (experimental):
Node.js now exposes the experimental implementation of the Web Streams
API on the global scope. This means the following APIs are now globally
available:
- `ReadableStream`, `ReadableStreamDefaultReader`,
`ReadableStreamBYOBReader`, `ReadableStreamBYOBRequest`,
`ReadableByteStreamController`, `ReadableStreamDefaultController`,
`TransformStream`, `TransformStreamDefaultController`, `WritableStream`,
`WritableStreamDefaultWriter`, `WritableStreamDefaultController`,
`ByteLengthQueuingStrategy`, `CountQueuingStrategy`, `TextEncoderStream`,
`TextDecoderStream`, `CompressionStream`, `DecompressionStream`.
Contributed James Snell in https://github.com/nodejs/node/pull/39062,
and Antoine du Hamel in https://github.com/nodejs/node/pull/42225.
Other Notable Changes:
- (SEMVER-MAJOR) buffer: expose Blob as a global
(James M Snell) (https://github.com/nodejs/node/pull/41270)
- (SEMVER-MAJOR) child\_process: improve argument validation
(Rich Trott) (https://github.com/nodejs/node/pull/41305)
- doc: add RafaelGSS to collaborators
(RafaelGSS) (https://github.com/nodejs/node/pull/42718)
- (SEMVER-MAJOR) http: make TCP noDelay enabled by default
(Paolo Insogna) (https://github.com/nodejs/node/pull/42163)
- (SEMVER-MAJOR) net: make `server.address()` return an integer for
`family`
(Antoine du Hamel) (https://github.com/nodejs/node/pull/41431)
- (SEMVER-MAJOR) worker: expose BroadcastChannel as a global
(James M Snell) (https://github.com/nodejs/node/pull/41271)
- (SEMVER-MAJOR) worker: graduate BroadcastChannel to supported
(James M Snell) (https://github.com/nodejs/node/pull/41271)
Semver-Major Commits:
- (SEMVER-MAJOR) assert,util: compare RegExp.lastIndex while using deep
equal checks
(Ruben Bridgewater) (https://github.com/nodejs/node/pull/41020)
- (SEMVER-MAJOR) buffer: refactor `byteLength` to remove outdated
optimizations
(Rongjian Zhang) (https://github.com/nodejs/node/pull/38545)
- (SEMVER-MAJOR) buffer: expose Blob as a global
(James M Snell) (https://github.com/nodejs/node/pull/41270)
- (SEMVER-MAJOR) buffer: graduate Blob from experimental
(James M Snell) (https://github.com/nodejs/node/pull/41270)
- (SEMVER-MAJOR) build: make x86 Windows support temporarily
experimental
(Michaël Zasso) (https://github.com/nodejs/node/pull/42666)
- (SEMVER-MAJOR) build: bump macOS deployment target to 10.15
(Richard Lau) (https://github.com/nodejs/node/pull/42292)
- (SEMVER-MAJOR) build: downgrade Windows 8.1 and server 2012 R2 to
experimental
(Michaël Zasso) (https://github.com/nodejs/node/pull/42105)
- (SEMVER-MAJOR) child\_process: improve argument validation
(Rich Trott) (https://github.com/nodejs/node/pull/41305)
- (SEMVER-MAJOR) cluster: make `kill` to be just `process.kill`
(Bar Admoni) (https://github.com/nodejs/node/pull/34312)
- (SEMVER-MAJOR) crypto: cleanup validation
(Mohammed Keyvanzadeh) (https://github.com/nodejs/node/pull/39841)
- (SEMVER-MAJOR) crypto: prettify othername in PrintGeneralName
(Tobias Nießen) (https://github.com/nodejs/node/pull/42123)
- (SEMVER-MAJOR) crypto: fix X509Certificate toLegacyObject
(Tobias Nießen) (https://github.com/nodejs/node/pull/42124)
- (SEMVER-MAJOR) crypto: use RFC2253 format in PrintGeneralName
(Tobias Nießen) (https://github.com/nodejs/node/pull/42002)
- (SEMVER-MAJOR) crypto: change default check(Host|Email) behavior
(Tobias Nießen) (https://github.com/nodejs/node/pull/41600)
- (SEMVER-MAJOR) deps: V8: cherry-pick semver-major commits from 10.2
(Michaël Zasso) (https://github.com/nodejs/node/pull/42657)
- (SEMVER-MAJOR) deps: update V8 to 10.1.124.6
(Michaël Zasso) (https://github.com/nodejs/node/pull/42657)
- (SEMVER-MAJOR) deps: update V8 to 9.8.177.9
(Michaël Zasso) (https://github.com/nodejs/node/pull/41610)
- (SEMVER-MAJOR) deps: update V8 to 9.7.106.18
(Michaël Zasso) (https://github.com/nodejs/node/pull/40907)
- (SEMVER-MAJOR) dns: remove `dns.lookup` and `dnsPromises.lookup`
options type coercion
(Antoine du Hamel) (https://github.com/nodejs/node/pull/41431)
- (SEMVER-MAJOR) doc: update minimum glibc requirements for Linux
(Richard Lau) (https://github.com/nodejs/node/pull/42659)
- (SEMVER-MAJOR) doc: update AIX minimum supported arch
(Richard Lau) (https://github.com/nodejs/node/pull/42604)
- (SEMVER-MAJOR) fs: runtime deprecate string coercion in `fs.write`,
`fs.writeFileSync`
(Livia Medeiros) (https://github.com/nodejs/node/pull/42607)
- (SEMVER-MAJOR) http: refactor headersTimeout and requestTimeout logic
(Paolo Insogna) (https://github.com/nodejs/node/pull/41263)
- (SEMVER-MAJOR) http: make TCP noDelay enabled by default
(Paolo Insogna) (https://github.com/nodejs/node/pull/42163)
- (SEMVER-MAJOR) lib: enable fetch by default
(Michaël Zasso) (https://github.com/nodejs/node/pull/41811)
- (SEMVER-MAJOR) lib: replace validator and error
(Mohammed Keyvanzadeh) (https://github.com/nodejs/node/pull/41678)
- (SEMVER-MAJOR) module,repl: support 'node:'-only core modules
(Colin Ihrig) (https://github.com/nodejs/node/pull/42325)
- (SEMVER-MAJOR) net: make `server.address()` return an integer for
`family`
(Antoine du Hamel) (https://github.com/nodejs/node/pull/41431)
- (SEMVER-MAJOR) process: disallow some uses of Object.defineProperty()
on process.env
(Himself65) (https://github.com/nodejs/node/pull/28006)
- (SEMVER-MAJOR) process: runtime deprecate multipleResolves
(Benjamin Gruenbaum) (https://github.com/nodejs/node/pull/41896)
- (SEMVER-MAJOR) readline: fix question still called after closed
(Xuguang Mei) (https://github.com/nodejs/node/pull/42464)
- (SEMVER-MAJOR) stream: remove thenable support
(Robert Nagy) (https://github.com/nodejs/node/pull/40773)
- (SEMVER-MAJOR) stream: expose web streams globals, remove runtime
experimental warning
(Antoine du Hamel) (https://github.com/nodejs/node/pull/42225)
- (SEMVER-MAJOR) stream: need to cleanup event listeners if last stream
is readable
(Xuguang Mei) (https://github.com/nodejs/node/pull/41954)
- (SEMVER-MAJOR) stream: revert revert `map` spec compliance
(Benjamin Gruenbaum) (https://github.com/nodejs/node/pull/41933)
- (SEMVER-MAJOR) stream: throw invalid arg type from End Of Stream
(Jithil P Ponnan) (https://github.com/nodejs/node/pull/41766)
- (SEMVER-MAJOR) stream: don't emit finish after destroy
(Robert Nagy) (https://github.com/nodejs/node/pull/40852)
- (SEMVER-MAJOR) stream: add errored and closed props
(Robert Nagy) (https://github.com/nodejs/node/pull/40696)
- (SEMVER-MAJOR) test: add initial test module
(Colin Ihrig) (https://github.com/nodejs/node/pull/42325)
- (SEMVER-MAJOR) timers: refactor internal classes to ES2015 syntax
(Rabbit) (https://github.com/nodejs/node/pull/37408)
- (SEMVER-MAJOR) tls: represent registeredID numerically always
(Tobias Nießen) (https://github.com/nodejs/node/pull/41561)
- (SEMVER-MAJOR) tls: move tls.parseCertString to end-of-life
(Tobias Nießen) (https://github.com/nodejs/node/pull/41479)
- (SEMVER-MAJOR) url: throw on NULL in IPv6 hostname
(Rich Trott) (https://github.com/nodejs/node/pull/42313)
- (SEMVER-MAJOR) v8: make v8.writeHeapSnapshot() error codes consistent
(Darshan Sen) (https://github.com/nodejs/node/pull/42577)
- (SEMVER-MAJOR) v8: make writeHeapSnapshot throw if fopen fails
(Antonio Román) (https://github.com/nodejs/node/pull/41373)
- (SEMVER-MAJOR) worker: expose BroadcastChannel as a global
(James M Snell) (https://github.com/nodejs/node/pull/41271)
- (SEMVER-MAJOR) worker: graduate BroadcastChannel to supported
(James M Snell) (https://github.com/nodejs/node/pull/41271)
PR-URL: https://github.com/nodejs/node/pull/42262
2022-03-08 01:39:47 +00:00
|
|
|
- version: v18.0.0
|
2022-01-24 19:39:16 +03:30
|
|
|
pr-url: https://github.com/nodejs/node/pull/41678
|
|
|
|
description: Passing an invalid callback to the `callback` argument
|
|
|
|
now throws `ERR_INVALID_ARG_TYPE` instead of
|
|
|
|
`ERR_INVALID_CALLBACK`.
|
2016-06-30 08:52:44 +02:00
|
|
|
-->
|
2016-05-23 14:12:20 -07:00
|
|
|
|
|
|
|
* `callback` {Function} The function to call when the timer elapses.
|
|
|
|
* `delay` {number} The number of milliseconds to wait before calling the
|
2021-02-15 13:21:50 -05:00
|
|
|
`callback`. **Default:** `1`.
|
2016-08-29 22:35:03 -07:00
|
|
|
* `...args` {any} Optional arguments to pass when the `callback` is called.
|
2018-04-26 02:49:11 +03:00
|
|
|
* Returns: {Timeout} for use with [`clearInterval()`][]
|
2010-10-28 23:18:16 +11:00
|
|
|
|
2016-03-21 16:03:41 -07:00
|
|
|
Schedules repeated execution of `callback` every `delay` milliseconds.
|
2010-10-28 23:18:16 +11:00
|
|
|
|
2024-06-28 21:06:31 +09:30
|
|
|
When `delay` is larger than `2147483647` or less than `1` or `NaN`, the `delay`
|
|
|
|
will be set to `1`. Non-integer delays are truncated to an integer.
|
2015-10-24 23:56:49 -02:00
|
|
|
|
2016-05-23 14:12:20 -07:00
|
|
|
If `callback` is not a function, a [`TypeError`][] will be thrown.
|
2015-12-20 12:30:04 +01:00
|
|
|
|
2021-06-26 16:03:02 -07:00
|
|
|
This method has a custom variant for promises that is available using
|
|
|
|
[`timersPromises.setInterval()`][].
|
|
|
|
|
2020-10-23 00:12:44 +03:00
|
|
|
### `setTimeout(callback[, delay[, ...args]])`
|
2021-10-10 21:55:04 -07:00
|
|
|
|
2016-06-30 08:52:44 +02:00
|
|
|
<!-- YAML
|
|
|
|
added: v0.0.1
|
2022-01-24 19:39:16 +03:30
|
|
|
changes:
|
2022-04-19, Version 18.0.0 (Current)
Notable Changes:
Deprecations and Removals:
- (SEMVER-MAJOR) fs: runtime deprecate string coercion in `fs.write`,
`fs.writeFileSync`
(Livia Medeiros) (https://github.com/nodejs/node/pull/42607)
- (SEMVER-MAJOR) dns: remove `dns.lookup` and `dnsPromises.lookup`
options type coercion
(Antoine du Hamel) (https://github.com/nodejs/node/pull/41431)
- (SEMVER-MAJOR) process: runtime deprecate multipleResolves
(Benjamin Gruenbaum) (https://github.com/nodejs/node/pull/41896)
- (SEMVER-MAJOR) stream: remove thenable support (Robert Nagy)
(https://github.com/nodejs/node/pull/40773)
- (SEMVER-MAJOR) tls: move tls.parseCertString to end-of-life
(Tobias Nießen) (https://github.com/nodejs/node/pull/41479)
fetch (experimental):
An experimental fetch API is available on the global scope by default.
The implementation is based upon https://undici.nodejs.org/#/,
an HTTP/1.1 client written for Node.js by contributors to the project.
Through this addition, the following globals are made available: `fetch`
, `FormData`, `Headers`, `Request`, `Response`.
Disable this API with the `--no-experimental-fetch` command-line flag.
Contributed by Michaël Zasso in https://github.com/nodejs/node/pull/41811.
HTTP Timeouts:
`server.headersTimeout`, which limits the amount of time the parser will
wait to receive the complete HTTP headers, is now set to `60000` (60
seconds) by default.
`server.requestTimeout`, which sets the timeout value in milliseconds
for receiving the entire request from the client, is now set to `300000`
(5 minutes) by default.
If these timeouts expire, the server responds with status 408 without
forwarding the request to the request listener and then closes the
connection.
Both timeouts must be set to a non-zero value to protect against
potential Denial-of-Service attacks in case the server is deployed
without a reverse proxy in front.
Contributed by Paolo Insogna in https://github.com/nodejs/node/pull/41263.
Test Runner module (experimental):
The `node:test` module facilitates the creation of JavaScript tests that
report results in TAP format. This module is only available under the
`node:` scheme.
Contributed by Colin Ihrig in https://github.com/nodejs/node/pull/42325.
Toolchain and Compiler Upgrades:
- Prebuilt binaries for Linux are now built on Red Hat Enterprise Linux
(RHEL) 8 and are compatible with Linux distributions based on glibc
2.28 or later, for example, Debian 10, RHEL 8, Ubuntu 20.04.
- Prebuilt binaries for macOS now require macOS 10.15 or later.
- For AIX the minimum supported architecture has been raised from Power
7 to Power 8.
Prebuilt binaries for 32-bit Windows will initially not be available due
to issues building the V8 dependency in Node.js. We hope to restore
32-bit Windows binaries for Node.js 18 with a future V8 update.
Node.js does not support running on operating systems that are no longer
supported by their vendor. For operating systems where their vendor has
planned to end support earlier than April 2025, such as Windows 8.1
(January 2023) and Windows Server 2012 R2 (October 2023), support for
Node.js 18 will end at the earlier date.
Full details about the supported toolchains and compilers are documented
in the Node.js `BUILDING.md` file.
Contributed by Richard Lau in https://github.com/nodejs/node/pull/42292,
https://github.com/nodejs/node/pull/42604 and https://github.com/nodejs/node/pull/42659
, and Michaël Zasso in https://github.com/nodejs/node/pull/42105 and
https://github.com/nodejs/node/pull/42666.
V8 10.1:
The V8 engine is updated to version 10.1, which is part of Chromium 101.
Compared to the version included in Node.js 17.9.0, the following new
features are included:
- The `findLast` and `findLastIndex` array methods.
- Improvements to the `Intl.Locale` API.
- The `Intl.supportedValuesOf` function.
- Improved performance of class fields and private class methods (the
initialization of them is now as fast as ordinary property stores).
The data format returned by the serialization API (`v8.serialize(value)`)
has changed, and cannot be deserialized by earlier versions of Node.js.
On the other hand, it is still possible to deserialize the previous
format, as the API is backwards-compatible.
Contributed by Michaël Zasso in https://github.com/nodejs/node/pull/42657.
Web Streams API (experimental):
Node.js now exposes the experimental implementation of the Web Streams
API on the global scope. This means the following APIs are now globally
available:
- `ReadableStream`, `ReadableStreamDefaultReader`,
`ReadableStreamBYOBReader`, `ReadableStreamBYOBRequest`,
`ReadableByteStreamController`, `ReadableStreamDefaultController`,
`TransformStream`, `TransformStreamDefaultController`, `WritableStream`,
`WritableStreamDefaultWriter`, `WritableStreamDefaultController`,
`ByteLengthQueuingStrategy`, `CountQueuingStrategy`, `TextEncoderStream`,
`TextDecoderStream`, `CompressionStream`, `DecompressionStream`.
Contributed James Snell in https://github.com/nodejs/node/pull/39062,
and Antoine du Hamel in https://github.com/nodejs/node/pull/42225.
Other Notable Changes:
- (SEMVER-MAJOR) buffer: expose Blob as a global
(James M Snell) (https://github.com/nodejs/node/pull/41270)
- (SEMVER-MAJOR) child\_process: improve argument validation
(Rich Trott) (https://github.com/nodejs/node/pull/41305)
- doc: add RafaelGSS to collaborators
(RafaelGSS) (https://github.com/nodejs/node/pull/42718)
- (SEMVER-MAJOR) http: make TCP noDelay enabled by default
(Paolo Insogna) (https://github.com/nodejs/node/pull/42163)
- (SEMVER-MAJOR) net: make `server.address()` return an integer for
`family`
(Antoine du Hamel) (https://github.com/nodejs/node/pull/41431)
- (SEMVER-MAJOR) worker: expose BroadcastChannel as a global
(James M Snell) (https://github.com/nodejs/node/pull/41271)
- (SEMVER-MAJOR) worker: graduate BroadcastChannel to supported
(James M Snell) (https://github.com/nodejs/node/pull/41271)
Semver-Major Commits:
- (SEMVER-MAJOR) assert,util: compare RegExp.lastIndex while using deep
equal checks
(Ruben Bridgewater) (https://github.com/nodejs/node/pull/41020)
- (SEMVER-MAJOR) buffer: refactor `byteLength` to remove outdated
optimizations
(Rongjian Zhang) (https://github.com/nodejs/node/pull/38545)
- (SEMVER-MAJOR) buffer: expose Blob as a global
(James M Snell) (https://github.com/nodejs/node/pull/41270)
- (SEMVER-MAJOR) buffer: graduate Blob from experimental
(James M Snell) (https://github.com/nodejs/node/pull/41270)
- (SEMVER-MAJOR) build: make x86 Windows support temporarily
experimental
(Michaël Zasso) (https://github.com/nodejs/node/pull/42666)
- (SEMVER-MAJOR) build: bump macOS deployment target to 10.15
(Richard Lau) (https://github.com/nodejs/node/pull/42292)
- (SEMVER-MAJOR) build: downgrade Windows 8.1 and server 2012 R2 to
experimental
(Michaël Zasso) (https://github.com/nodejs/node/pull/42105)
- (SEMVER-MAJOR) child\_process: improve argument validation
(Rich Trott) (https://github.com/nodejs/node/pull/41305)
- (SEMVER-MAJOR) cluster: make `kill` to be just `process.kill`
(Bar Admoni) (https://github.com/nodejs/node/pull/34312)
- (SEMVER-MAJOR) crypto: cleanup validation
(Mohammed Keyvanzadeh) (https://github.com/nodejs/node/pull/39841)
- (SEMVER-MAJOR) crypto: prettify othername in PrintGeneralName
(Tobias Nießen) (https://github.com/nodejs/node/pull/42123)
- (SEMVER-MAJOR) crypto: fix X509Certificate toLegacyObject
(Tobias Nießen) (https://github.com/nodejs/node/pull/42124)
- (SEMVER-MAJOR) crypto: use RFC2253 format in PrintGeneralName
(Tobias Nießen) (https://github.com/nodejs/node/pull/42002)
- (SEMVER-MAJOR) crypto: change default check(Host|Email) behavior
(Tobias Nießen) (https://github.com/nodejs/node/pull/41600)
- (SEMVER-MAJOR) deps: V8: cherry-pick semver-major commits from 10.2
(Michaël Zasso) (https://github.com/nodejs/node/pull/42657)
- (SEMVER-MAJOR) deps: update V8 to 10.1.124.6
(Michaël Zasso) (https://github.com/nodejs/node/pull/42657)
- (SEMVER-MAJOR) deps: update V8 to 9.8.177.9
(Michaël Zasso) (https://github.com/nodejs/node/pull/41610)
- (SEMVER-MAJOR) deps: update V8 to 9.7.106.18
(Michaël Zasso) (https://github.com/nodejs/node/pull/40907)
- (SEMVER-MAJOR) dns: remove `dns.lookup` and `dnsPromises.lookup`
options type coercion
(Antoine du Hamel) (https://github.com/nodejs/node/pull/41431)
- (SEMVER-MAJOR) doc: update minimum glibc requirements for Linux
(Richard Lau) (https://github.com/nodejs/node/pull/42659)
- (SEMVER-MAJOR) doc: update AIX minimum supported arch
(Richard Lau) (https://github.com/nodejs/node/pull/42604)
- (SEMVER-MAJOR) fs: runtime deprecate string coercion in `fs.write`,
`fs.writeFileSync`
(Livia Medeiros) (https://github.com/nodejs/node/pull/42607)
- (SEMVER-MAJOR) http: refactor headersTimeout and requestTimeout logic
(Paolo Insogna) (https://github.com/nodejs/node/pull/41263)
- (SEMVER-MAJOR) http: make TCP noDelay enabled by default
(Paolo Insogna) (https://github.com/nodejs/node/pull/42163)
- (SEMVER-MAJOR) lib: enable fetch by default
(Michaël Zasso) (https://github.com/nodejs/node/pull/41811)
- (SEMVER-MAJOR) lib: replace validator and error
(Mohammed Keyvanzadeh) (https://github.com/nodejs/node/pull/41678)
- (SEMVER-MAJOR) module,repl: support 'node:'-only core modules
(Colin Ihrig) (https://github.com/nodejs/node/pull/42325)
- (SEMVER-MAJOR) net: make `server.address()` return an integer for
`family`
(Antoine du Hamel) (https://github.com/nodejs/node/pull/41431)
- (SEMVER-MAJOR) process: disallow some uses of Object.defineProperty()
on process.env
(Himself65) (https://github.com/nodejs/node/pull/28006)
- (SEMVER-MAJOR) process: runtime deprecate multipleResolves
(Benjamin Gruenbaum) (https://github.com/nodejs/node/pull/41896)
- (SEMVER-MAJOR) readline: fix question still called after closed
(Xuguang Mei) (https://github.com/nodejs/node/pull/42464)
- (SEMVER-MAJOR) stream: remove thenable support
(Robert Nagy) (https://github.com/nodejs/node/pull/40773)
- (SEMVER-MAJOR) stream: expose web streams globals, remove runtime
experimental warning
(Antoine du Hamel) (https://github.com/nodejs/node/pull/42225)
- (SEMVER-MAJOR) stream: need to cleanup event listeners if last stream
is readable
(Xuguang Mei) (https://github.com/nodejs/node/pull/41954)
- (SEMVER-MAJOR) stream: revert revert `map` spec compliance
(Benjamin Gruenbaum) (https://github.com/nodejs/node/pull/41933)
- (SEMVER-MAJOR) stream: throw invalid arg type from End Of Stream
(Jithil P Ponnan) (https://github.com/nodejs/node/pull/41766)
- (SEMVER-MAJOR) stream: don't emit finish after destroy
(Robert Nagy) (https://github.com/nodejs/node/pull/40852)
- (SEMVER-MAJOR) stream: add errored and closed props
(Robert Nagy) (https://github.com/nodejs/node/pull/40696)
- (SEMVER-MAJOR) test: add initial test module
(Colin Ihrig) (https://github.com/nodejs/node/pull/42325)
- (SEMVER-MAJOR) timers: refactor internal classes to ES2015 syntax
(Rabbit) (https://github.com/nodejs/node/pull/37408)
- (SEMVER-MAJOR) tls: represent registeredID numerically always
(Tobias Nießen) (https://github.com/nodejs/node/pull/41561)
- (SEMVER-MAJOR) tls: move tls.parseCertString to end-of-life
(Tobias Nießen) (https://github.com/nodejs/node/pull/41479)
- (SEMVER-MAJOR) url: throw on NULL in IPv6 hostname
(Rich Trott) (https://github.com/nodejs/node/pull/42313)
- (SEMVER-MAJOR) v8: make v8.writeHeapSnapshot() error codes consistent
(Darshan Sen) (https://github.com/nodejs/node/pull/42577)
- (SEMVER-MAJOR) v8: make writeHeapSnapshot throw if fopen fails
(Antonio Román) (https://github.com/nodejs/node/pull/41373)
- (SEMVER-MAJOR) worker: expose BroadcastChannel as a global
(James M Snell) (https://github.com/nodejs/node/pull/41271)
- (SEMVER-MAJOR) worker: graduate BroadcastChannel to supported
(James M Snell) (https://github.com/nodejs/node/pull/41271)
PR-URL: https://github.com/nodejs/node/pull/42262
2022-03-08 01:39:47 +00:00
|
|
|
- version: v18.0.0
|
2022-01-24 19:39:16 +03:30
|
|
|
pr-url: https://github.com/nodejs/node/pull/41678
|
|
|
|
description: Passing an invalid callback to the `callback` argument
|
|
|
|
now throws `ERR_INVALID_ARG_TYPE` instead of
|
|
|
|
`ERR_INVALID_CALLBACK`.
|
2016-06-30 08:52:44 +02:00
|
|
|
-->
|
2016-05-23 14:12:20 -07:00
|
|
|
|
|
|
|
* `callback` {Function} The function to call when the timer elapses.
|
|
|
|
* `delay` {number} The number of milliseconds to wait before calling the
|
2021-02-15 13:21:50 -05:00
|
|
|
`callback`. **Default:** `1`.
|
2016-08-29 22:35:03 -07:00
|
|
|
* `...args` {any} Optional arguments to pass when the `callback` is called.
|
2018-04-26 02:49:11 +03:00
|
|
|
* Returns: {Timeout} for use with [`clearTimeout()`][]
|
2010-10-28 23:18:16 +11:00
|
|
|
|
2016-03-21 16:03:41 -07:00
|
|
|
Schedules execution of a one-time `callback` after `delay` milliseconds.
|
2015-11-04 12:35:20 -05:00
|
|
|
|
2016-05-23 14:12:20 -07:00
|
|
|
The `callback` will likely not be invoked in precisely `delay` milliseconds.
|
2015-12-26 18:39:16 -08:00
|
|
|
Node.js makes no guarantees about the exact timing of when callbacks will fire,
|
|
|
|
nor of their ordering. The callback will be called as close as possible to the
|
|
|
|
time specified.
|
2015-11-04 12:35:20 -05:00
|
|
|
|
2024-06-28 21:06:31 +09:30
|
|
|
When `delay` is larger than `2147483647` or less than `1` or `NaN`, the `delay`
|
2018-12-03 17:41:58 -08:00
|
|
|
will be set to `1`. Non-integer delays are truncated to an integer.
|
2016-05-23 14:12:20 -07:00
|
|
|
|
|
|
|
If `callback` is not a function, a [`TypeError`][] will be thrown.
|
|
|
|
|
2018-02-05 21:55:16 -08:00
|
|
|
This method has a custom variant for promises that is available using
|
2021-06-26 16:03:02 -07:00
|
|
|
[`timersPromises.setTimeout()`][].
|
2017-04-14 21:42:47 +02:00
|
|
|
|
2020-06-14 14:49:34 -07:00
|
|
|
## Cancelling timers
|
2016-05-23 14:12:20 -07:00
|
|
|
|
|
|
|
The [`setImmediate()`][], [`setInterval()`][], and [`setTimeout()`][] methods
|
|
|
|
each return objects that represent the scheduled timers. These can be used to
|
|
|
|
cancel the timer and prevent it from triggering.
|
|
|
|
|
2020-06-10 14:14:23 -07:00
|
|
|
For the promisified variants of [`setImmediate()`][] and [`setTimeout()`][],
|
|
|
|
an [`AbortController`][] may be used to cancel the timer. When canceled, the
|
|
|
|
returned Promises will be rejected with an `'AbortError'`.
|
|
|
|
|
|
|
|
For `setImmediate()`:
|
|
|
|
|
2024-11-20 20:26:30 -03:00
|
|
|
```mjs
|
|
|
|
import { setImmediate as setImmediatePromise } from 'node:timers/promises';
|
|
|
|
|
|
|
|
const ac = new AbortController();
|
|
|
|
const signal = ac.signal;
|
|
|
|
|
|
|
|
// We do not `await` the promise so `ac.abort()` is called concurrently.
|
|
|
|
setImmediatePromise('foobar', { signal })
|
|
|
|
.then(console.log)
|
|
|
|
.catch((err) => {
|
|
|
|
if (err.name === 'AbortError')
|
|
|
|
console.error('The immediate was aborted');
|
|
|
|
});
|
|
|
|
|
|
|
|
ac.abort();
|
|
|
|
```
|
|
|
|
|
|
|
|
```cjs
|
2022-04-20 10:23:41 +02:00
|
|
|
const { setImmediate: setImmediatePromise } = require('node:timers/promises');
|
2020-06-10 14:14:23 -07:00
|
|
|
|
|
|
|
const ac = new AbortController();
|
|
|
|
const signal = ac.signal;
|
|
|
|
|
|
|
|
setImmediatePromise('foobar', { signal })
|
|
|
|
.then(console.log)
|
|
|
|
.catch((err) => {
|
2021-03-13 10:54:10 +02:00
|
|
|
if (err.name === 'AbortError')
|
2023-01-01 15:41:28 +09:00
|
|
|
console.error('The immediate was aborted');
|
2020-06-10 14:14:23 -07:00
|
|
|
});
|
|
|
|
|
|
|
|
ac.abort();
|
|
|
|
```
|
|
|
|
|
|
|
|
For `setTimeout()`:
|
|
|
|
|
2024-11-20 20:26:30 -03:00
|
|
|
```mjs
|
|
|
|
import { setTimeout as setTimeoutPromise } from 'node:timers/promises';
|
|
|
|
|
|
|
|
const ac = new AbortController();
|
|
|
|
const signal = ac.signal;
|
|
|
|
|
|
|
|
// We do not `await` the promise so `ac.abort()` is called concurrently.
|
|
|
|
setTimeoutPromise(1000, 'foobar', { signal })
|
|
|
|
.then(console.log)
|
|
|
|
.catch((err) => {
|
|
|
|
if (err.name === 'AbortError')
|
|
|
|
console.error('The timeout was aborted');
|
|
|
|
});
|
|
|
|
|
|
|
|
ac.abort();
|
|
|
|
```
|
|
|
|
|
|
|
|
```cjs
|
2022-04-20 10:23:41 +02:00
|
|
|
const { setTimeout: setTimeoutPromise } = require('node:timers/promises');
|
2020-06-10 14:14:23 -07:00
|
|
|
|
|
|
|
const ac = new AbortController();
|
|
|
|
const signal = ac.signal;
|
|
|
|
|
|
|
|
setTimeoutPromise(1000, 'foobar', { signal })
|
|
|
|
.then(console.log)
|
|
|
|
.catch((err) => {
|
2021-03-13 10:54:10 +02:00
|
|
|
if (err.name === 'AbortError')
|
2023-01-01 15:41:28 +09:00
|
|
|
console.error('The timeout was aborted');
|
2020-06-10 14:14:23 -07:00
|
|
|
});
|
|
|
|
|
|
|
|
ac.abort();
|
|
|
|
```
|
2017-04-14 21:42:47 +02:00
|
|
|
|
2019-12-24 15:11:21 -08:00
|
|
|
### `clearImmediate(immediate)`
|
2021-10-10 21:55:04 -07:00
|
|
|
|
2016-06-30 08:52:44 +02:00
|
|
|
<!-- YAML
|
|
|
|
added: v0.9.1
|
|
|
|
-->
|
2016-05-23 14:12:20 -07:00
|
|
|
|
|
|
|
* `immediate` {Immediate} An `Immediate` object as returned by
|
|
|
|
[`setImmediate()`][].
|
|
|
|
|
|
|
|
Cancels an `Immediate` object created by [`setImmediate()`][].
|
|
|
|
|
2019-12-24 15:11:21 -08:00
|
|
|
### `clearInterval(timeout)`
|
2021-10-10 21:55:04 -07:00
|
|
|
|
2016-06-30 08:52:44 +02:00
|
|
|
<!-- YAML
|
|
|
|
added: v0.0.1
|
|
|
|
-->
|
2016-05-23 14:12:20 -07:00
|
|
|
|
2021-06-12 16:50:55 +04:30
|
|
|
* `timeout` {Timeout|string|number} A `Timeout` object as returned by [`setInterval()`][]
|
|
|
|
or the [primitive][] of the `Timeout` object as a string or a number.
|
2012-07-13 15:08:32 -04:00
|
|
|
|
2016-05-23 14:12:20 -07:00
|
|
|
Cancels a `Timeout` object created by [`setInterval()`][].
|
2015-12-20 12:30:04 +01:00
|
|
|
|
2019-12-24 15:11:21 -08:00
|
|
|
### `clearTimeout(timeout)`
|
2021-10-10 21:55:04 -07:00
|
|
|
|
2016-06-30 08:52:44 +02:00
|
|
|
<!-- YAML
|
|
|
|
added: v0.0.1
|
|
|
|
-->
|
2012-07-13 15:08:32 -04:00
|
|
|
|
2021-06-12 16:50:55 +04:30
|
|
|
* `timeout` {Timeout|string|number} A `Timeout` object as returned by [`setTimeout()`][]
|
|
|
|
or the [primitive][] of the `Timeout` object as a string or a number.
|
2012-07-13 15:08:32 -04:00
|
|
|
|
2016-05-23 14:12:20 -07:00
|
|
|
Cancels a `Timeout` object created by [`setTimeout()`][].
|
2012-07-13 15:08:32 -04:00
|
|
|
|
2020-06-18 13:22:17 -07:00
|
|
|
## Timers Promises API
|
2021-10-10 21:55:04 -07:00
|
|
|
|
2020-12-03 22:21:52 -05:00
|
|
|
<!-- YAML
|
|
|
|
added: v15.0.0
|
2021-04-06 10:00:37 -07:00
|
|
|
changes:
|
2021-03-03 15:36:13 +00:00
|
|
|
- version: v16.0.0
|
2021-04-06 10:00:37 -07:00
|
|
|
pr-url: https://github.com/nodejs/node/pull/38112
|
|
|
|
description: Graduated from experimental.
|
2020-12-03 22:21:52 -05:00
|
|
|
-->
|
2020-06-18 13:22:17 -07:00
|
|
|
|
|
|
|
The `timers/promises` API provides an alternative set of timer functions
|
|
|
|
that return `Promise` objects. The API is accessible via
|
2022-04-20 10:23:41 +02:00
|
|
|
`require('node:timers/promises')`.
|
2020-06-18 13:22:17 -07:00
|
|
|
|
2021-04-06 10:00:37 -07:00
|
|
|
```mjs
|
|
|
|
import {
|
|
|
|
setTimeout,
|
|
|
|
setImmediate,
|
|
|
|
setInterval,
|
2024-07-21 17:44:27 +02:00
|
|
|
} from 'node:timers/promises';
|
2021-04-06 10:00:37 -07:00
|
|
|
```
|
|
|
|
|
|
|
|
```cjs
|
|
|
|
const {
|
|
|
|
setTimeout,
|
|
|
|
setImmediate,
|
|
|
|
setInterval,
|
2022-04-20 10:23:41 +02:00
|
|
|
} = require('node:timers/promises');
|
2020-06-18 13:22:17 -07:00
|
|
|
```
|
|
|
|
|
2020-10-23 00:12:44 +03:00
|
|
|
### `timersPromises.setTimeout([delay[, value[, options]]])`
|
2021-10-10 21:55:04 -07:00
|
|
|
|
2020-12-03 22:21:52 -05:00
|
|
|
<!-- YAML
|
|
|
|
added: v15.0.0
|
|
|
|
-->
|
2020-06-18 13:22:17 -07:00
|
|
|
|
2021-04-06 10:00:37 -07:00
|
|
|
* `delay` {number} The number of milliseconds to wait before fulfilling the
|
|
|
|
promise. **Default:** `1`.
|
|
|
|
* `value` {any} A value with which the promise is fulfilled.
|
2020-06-18 13:22:17 -07:00
|
|
|
* `options` {Object}
|
|
|
|
* `ref` {boolean} Set to `false` to indicate that the scheduled `Timeout`
|
|
|
|
should not require the Node.js event loop to remain active.
|
2021-02-15 13:21:50 -05:00
|
|
|
**Default:** `true`.
|
2020-06-18 13:22:17 -07:00
|
|
|
* `signal` {AbortSignal} An optional `AbortSignal` that can be used to
|
|
|
|
cancel the scheduled `Timeout`.
|
|
|
|
|
2021-04-06 10:00:37 -07:00
|
|
|
```mjs
|
|
|
|
import {
|
|
|
|
setTimeout,
|
2024-07-21 17:44:27 +02:00
|
|
|
} from 'node:timers/promises';
|
2021-04-06 10:00:37 -07:00
|
|
|
|
|
|
|
const res = await setTimeout(100, 'result');
|
|
|
|
|
|
|
|
console.log(res); // Prints 'result'
|
|
|
|
```
|
|
|
|
|
|
|
|
```cjs
|
|
|
|
const {
|
|
|
|
setTimeout,
|
2022-04-20 10:23:41 +02:00
|
|
|
} = require('node:timers/promises');
|
2021-04-06 10:00:37 -07:00
|
|
|
|
|
|
|
setTimeout(100, 'result').then((res) => {
|
|
|
|
console.log(res); // Prints 'result'
|
|
|
|
});
|
|
|
|
```
|
|
|
|
|
2020-10-23 00:12:44 +03:00
|
|
|
### `timersPromises.setImmediate([value[, options]])`
|
2021-10-10 21:55:04 -07:00
|
|
|
|
2020-12-03 22:21:52 -05:00
|
|
|
<!-- YAML
|
|
|
|
added: v15.0.0
|
|
|
|
-->
|
2020-06-18 13:22:17 -07:00
|
|
|
|
2021-04-06 10:00:37 -07:00
|
|
|
* `value` {any} A value with which the promise is fulfilled.
|
2020-06-18 13:22:17 -07:00
|
|
|
* `options` {Object}
|
|
|
|
* `ref` {boolean} Set to `false` to indicate that the scheduled `Immediate`
|
|
|
|
should not require the Node.js event loop to remain active.
|
2021-02-15 13:21:50 -05:00
|
|
|
**Default:** `true`.
|
2020-06-18 13:22:17 -07:00
|
|
|
* `signal` {AbortSignal} An optional `AbortSignal` that can be used to
|
|
|
|
cancel the scheduled `Immediate`.
|
|
|
|
|
2021-04-06 10:00:37 -07:00
|
|
|
```mjs
|
|
|
|
import {
|
|
|
|
setImmediate,
|
2024-07-21 17:44:27 +02:00
|
|
|
} from 'node:timers/promises';
|
2021-04-06 10:00:37 -07:00
|
|
|
|
|
|
|
const res = await setImmediate('result');
|
|
|
|
|
|
|
|
console.log(res); // Prints 'result'
|
|
|
|
```
|
|
|
|
|
|
|
|
```cjs
|
|
|
|
const {
|
|
|
|
setImmediate,
|
2022-04-20 10:23:41 +02:00
|
|
|
} = require('node:timers/promises');
|
2021-04-06 10:00:37 -07:00
|
|
|
|
|
|
|
setImmediate('result').then((res) => {
|
|
|
|
console.log(res); // Prints 'result'
|
|
|
|
});
|
|
|
|
```
|
|
|
|
|
2021-01-31 01:16:18 +02:00
|
|
|
### `timersPromises.setInterval([delay[, value[, options]]])`
|
2021-10-10 21:55:04 -07:00
|
|
|
|
2021-01-31 01:16:18 +02:00
|
|
|
<!-- YAML
|
2021-02-17 08:16:22 -05:00
|
|
|
added: v15.9.0
|
2021-01-31 01:16:18 +02:00
|
|
|
-->
|
|
|
|
|
|
|
|
Returns an async iterator that generates values in an interval of `delay` ms.
|
2022-11-07 01:45:23 +08:00
|
|
|
If `ref` is `true`, you need to call `next()` of async iterator explicitly
|
|
|
|
or implicitly to keep the event loop alive.
|
2021-01-31 01:16:18 +02:00
|
|
|
|
|
|
|
* `delay` {number} The number of milliseconds to wait between iterations.
|
2021-10-10 21:55:04 -07:00
|
|
|
**Default:** `1`.
|
2021-01-31 01:16:18 +02:00
|
|
|
* `value` {any} A value with which the iterator returns.
|
|
|
|
* `options` {Object}
|
|
|
|
* `ref` {boolean} Set to `false` to indicate that the scheduled `Timeout`
|
|
|
|
between iterations should not require the Node.js event loop to
|
|
|
|
remain active.
|
2021-02-15 13:21:50 -05:00
|
|
|
**Default:** `true`.
|
2021-01-31 01:16:18 +02:00
|
|
|
* `signal` {AbortSignal} An optional `AbortSignal` that can be used to
|
|
|
|
cancel the scheduled `Timeout` between operations.
|
|
|
|
|
2021-04-06 10:00:37 -07:00
|
|
|
```mjs
|
|
|
|
import {
|
|
|
|
setInterval,
|
2024-07-21 17:44:27 +02:00
|
|
|
} from 'node:timers/promises';
|
2021-04-06 10:00:37 -07:00
|
|
|
|
|
|
|
const interval = 100;
|
|
|
|
for await (const startTime of setInterval(interval, Date.now())) {
|
|
|
|
const now = Date.now();
|
|
|
|
console.log(now);
|
|
|
|
if ((now - startTime) > 1000)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
console.log(Date.now());
|
|
|
|
```
|
|
|
|
|
|
|
|
```cjs
|
|
|
|
const {
|
|
|
|
setInterval,
|
2022-04-20 10:23:41 +02:00
|
|
|
} = require('node:timers/promises');
|
2021-04-06 10:00:37 -07:00
|
|
|
const interval = 100;
|
|
|
|
|
2021-01-31 01:16:18 +02:00
|
|
|
(async function() {
|
|
|
|
for await (const startTime of setInterval(interval, Date.now())) {
|
|
|
|
const now = Date.now();
|
|
|
|
console.log(now);
|
|
|
|
if ((now - startTime) > 1000)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
console.log(Date.now());
|
|
|
|
})();
|
|
|
|
```
|
|
|
|
|
2021-11-21 08:04:21 -08:00
|
|
|
### `timersPromises.scheduler.wait(delay[, options])`
|
|
|
|
|
|
|
|
<!-- YAML
|
2022-02-01 00:34:51 -05:00
|
|
|
added:
|
|
|
|
- v17.3.0
|
|
|
|
- v16.14.0
|
2021-11-21 08:04:21 -08:00
|
|
|
-->
|
|
|
|
|
|
|
|
> Stability: 1 - Experimental
|
|
|
|
|
|
|
|
* `delay` {number} The number of milliseconds to wait before resolving the
|
|
|
|
promise.
|
|
|
|
* `options` {Object}
|
2024-09-02 08:57:02 +02:00
|
|
|
* `ref` {boolean} Set to `false` to indicate that the scheduled `Timeout`
|
|
|
|
should not require the Node.js event loop to remain active.
|
|
|
|
**Default:** `true`.
|
2021-11-21 08:04:21 -08:00
|
|
|
* `signal` {AbortSignal} An optional `AbortSignal` that can be used to
|
|
|
|
cancel waiting.
|
|
|
|
* Returns: {Promise}
|
|
|
|
|
|
|
|
An experimental API defined by the [Scheduling APIs][] draft specification
|
|
|
|
being developed as a standard Web Platform API.
|
|
|
|
|
2024-08-25 09:30:10 +02:00
|
|
|
Calling `timersPromises.scheduler.wait(delay, options)` is equivalent
|
|
|
|
to calling `timersPromises.setTimeout(delay, undefined, options)`.
|
2021-11-21 08:04:21 -08:00
|
|
|
|
|
|
|
```mjs
|
2022-04-20 10:23:41 +02:00
|
|
|
import { scheduler } from 'node:timers/promises';
|
2021-11-21 08:04:21 -08:00
|
|
|
|
|
|
|
await scheduler.wait(1000); // Wait one second before continuing
|
|
|
|
```
|
|
|
|
|
|
|
|
### `timersPromises.scheduler.yield()`
|
|
|
|
|
|
|
|
<!-- YAML
|
2022-02-01 00:34:51 -05:00
|
|
|
added:
|
|
|
|
- v17.3.0
|
|
|
|
- v16.14.0
|
2021-11-21 08:04:21 -08:00
|
|
|
-->
|
|
|
|
|
|
|
|
> Stability: 1 - Experimental
|
|
|
|
|
|
|
|
* Returns: {Promise}
|
|
|
|
|
|
|
|
An experimental API defined by the [Scheduling APIs][] draft specification
|
|
|
|
being developed as a standard Web Platform API.
|
|
|
|
|
|
|
|
Calling `timersPromises.scheduler.yield()` is equivalent to calling
|
|
|
|
`timersPromises.setImmediate()` with no arguments.
|
|
|
|
|
2019-01-21 12:08:35 -08:00
|
|
|
[Event Loop]: https://nodejs.org/en/docs/guides/event-loop-timers-and-nexttick/#setimmediate-vs-settimeout
|
2021-11-21 08:04:21 -08:00
|
|
|
[Scheduling APIs]: https://github.com/WICG/scheduling-apis
|
2021-07-04 20:39:17 -07:00
|
|
|
[`AbortController`]: globals.md#class-abortcontroller
|
|
|
|
[`TypeError`]: errors.md#class-typeerror
|
|
|
|
[`clearImmediate()`]: #clearimmediateimmediate
|
|
|
|
[`clearInterval()`]: #clearintervaltimeout
|
|
|
|
[`clearTimeout()`]: #cleartimeouttimeout
|
|
|
|
[`setImmediate()`]: #setimmediatecallback-args
|
|
|
|
[`setInterval()`]: #setintervalcallback-delay-args
|
|
|
|
[`setTimeout()`]: #settimeoutcallback-delay-args
|
|
|
|
[`timersPromises.setImmediate()`]: #timerspromisessetimmediatevalue-options
|
|
|
|
[`timersPromises.setInterval()`]: #timerspromisessetintervaldelay-value-options
|
|
|
|
[`timersPromises.setTimeout()`]: #timerspromisessettimeoutdelay-value-options
|
2020-09-14 17:09:13 +02:00
|
|
|
[`worker_threads`]: worker_threads.md
|
2021-07-04 20:39:17 -07:00
|
|
|
[primitive]: #timeoutsymboltoprimitive
|