2020-08-21 16:25:39 -07:00
|
|
|
# Diagnostics Channel
|
|
|
|
|
2022-11-05 05:03:53 -07:00
|
|
|
<!-- YAML
|
2023-03-08 00:47:10 -08:00
|
|
|
added:
|
|
|
|
- v15.1.0
|
|
|
|
- v14.17.0
|
2022-11-05 05:03:53 -07:00
|
|
|
changes:
|
2023-01-05, Version 18.13.0 'Hydrogen' (LTS)
Notable changes:
Add support for externally shared js builtins:
By default Node.js is built so that all dependencies are bundled into the
Node.js binary itself. Some Node.js distributions prefer to manage dependencies
externally. There are existing build options that allow dependencies with
native code to be externalized. This commit adds additional options so that
dependencies with JavaScript code (including WASM) can also be externalized.
This addition does not affect binaries shipped by the Node.js project but
will allow other distributions to externalize additional dependencies when
needed.
Contributed by Michael Dawson in https://github.com/nodejs/node/pull/44376
Introduce `File`:
The File class is part of the [FileAPI](https://w3c.github.io/FileAPI/).
It can be used anywhere a Blob can, for example in `URL.createObjectURL`
and `FormData`. It contains two properties that Blobs do not have: `lastModified`,
the last time the file was modified in ms, and `name`, the name of the file.
Contributed by Khafra in https://github.com/nodejs/node/pull/45139
Support function mocking on Node.js test runner:
The `node:test` module supports mocking during testing via a top-level `mock`
object.
```js
test('spies on an object method', (t) => {
const number = {
value: 5,
add(a) {
return this.value + a;
},
};
t.mock.method(number, 'add');
assert.strictEqual(number.add(3), 8);
assert.strictEqual(number.add.mock.calls.length, 1);
});
```
Contributed by Colin Ihrig in https://github.com/nodejs/node/pull/45326
Other notable changes:
build:
* disable v8 snapshot compression by default (Joyee Cheung) https://github.com/nodejs/node/pull/45716
crypto:
* update root certificates (Luigi Pinca) https://github.com/nodejs/node/pull/45490
deps:
* update ICU to 72.1 (Michaël Zasso) https://github.com/nodejs/node/pull/45068
doc:
* add doc-only deprecation for headers/trailers setters (Rich Trott) https://github.com/nodejs/node/pull/45697
* add Rafael to the tsc (Michael Dawson) https://github.com/nodejs/node/pull/45691
* deprecate use of invalid ports in `url.parse` (Antoine du Hamel) https://github.com/nodejs/node/pull/45576
* add lukekarrys to collaborators (Luke Karrys) https://github.com/nodejs/node/pull/45180
* add anonrig to collaborators (Yagiz Nizipli) https://github.com/nodejs/node/pull/45002
* deprecate url.parse() (Rich Trott) https://github.com/nodejs/node/pull/44919
lib:
* drop fetch experimental warning (Matteo Collina) https://github.com/nodejs/node/pull/45287
net:
* (SEMVER-MINOR) add autoSelectFamily and autoSelectFamilyAttemptTimeout options (Paolo Insogna) https://github.com/nodejs/node/pull/44731
* src:
* (SEMVER-MINOR) add uvwasi version (Jithil P Ponnan) https://github.com/nodejs/node/pull/45639
* (SEMVER-MINOR) add initial shadow realm support (Chengzhong Wu) https://github.com/nodejs/node/pull/42869
test_runner:
* (SEMVER-MINOR) add t.after() hook (Colin Ihrig) https://github.com/nodejs/node/pull/45792
* (SEMVER-MINOR) don't use a symbol for runHook() (Colin Ihrig) https://github.com/nodejs/node/pull/45792
tls:
* (SEMVER-MINOR) add "ca" property to certificate object (Ben Noordhuis) https://github.com/nodejs/node/pull/44935
* remove trustcor root ca certificates (Ben Noordhuis) https://github.com/nodejs/node/pull/45776
tools:
* update certdata.txt (Luigi Pinca) https://github.com/nodejs/node/pull/45490
util:
* add fast path for utf8 encoding (Yagiz Nizipli) https://github.com/nodejs/node/pull/45412
* improve textdecoder decode performance (Yagiz Nizipli) https://github.com/nodejs/node/pull/45294
* (SEMVER-MINOR) add MIME utilities (#21128) (Bradley Farias) https://github.com/nodejs/node/pull/21128
PR-URL: https://github.com/nodejs/node/pull/46025
2022-12-30 15:18:44 -05:00
|
|
|
- version:
|
|
|
|
- v19.2.0
|
|
|
|
- v18.13.0
|
2022-11-05 05:03:53 -07:00
|
|
|
pr-url: https://github.com/nodejs/node/pull/45290
|
|
|
|
description: diagnostics_channel is now Stable.
|
|
|
|
-->
|
|
|
|
|
2020-11-03 17:57:08 +01:00
|
|
|
<!--introduced_in=v15.1.0-->
|
2020-08-21 16:25:39 -07:00
|
|
|
|
2022-11-05 05:03:53 -07:00
|
|
|
> Stability: 2 - Stable
|
2020-08-21 16:25:39 -07:00
|
|
|
|
|
|
|
<!-- source_link=lib/diagnostics_channel.js -->
|
|
|
|
|
2022-04-20 10:23:41 +02:00
|
|
|
The `node:diagnostics_channel` module provides an API to create named channels
|
2020-08-21 16:25:39 -07:00
|
|
|
to report arbitrary message data for diagnostics purposes.
|
|
|
|
|
|
|
|
It can be accessed using:
|
|
|
|
|
2021-06-15 10:09:29 -07:00
|
|
|
```mjs
|
2022-04-20 10:23:41 +02:00
|
|
|
import diagnostics_channel from 'node:diagnostics_channel';
|
2021-06-15 10:09:29 -07:00
|
|
|
```
|
|
|
|
|
|
|
|
```cjs
|
2022-04-20 10:23:41 +02:00
|
|
|
const diagnostics_channel = require('node:diagnostics_channel');
|
2020-08-21 16:25:39 -07:00
|
|
|
```
|
|
|
|
|
|
|
|
It is intended that a module writer wanting to report diagnostics messages
|
|
|
|
will create one or many top-level channels to report messages through.
|
|
|
|
Channels may also be acquired at runtime but it is not encouraged
|
|
|
|
due to the additional overhead of doing so. Channels may be exported for
|
|
|
|
convenience, but as long as the name is known it can be acquired anywhere.
|
|
|
|
|
|
|
|
If you intend for your module to produce diagnostics data for others to
|
|
|
|
consume it is recommended that you include documentation of what named
|
|
|
|
channels are used along with the shape of the message data. Channel names
|
|
|
|
should generally include the module name to avoid collisions with data from
|
|
|
|
other modules.
|
|
|
|
|
|
|
|
## Public API
|
|
|
|
|
|
|
|
### Overview
|
|
|
|
|
|
|
|
Following is a simple overview of the public API.
|
|
|
|
|
2021-06-15 10:09:29 -07:00
|
|
|
```mjs
|
2022-04-20 10:23:41 +02:00
|
|
|
import diagnostics_channel from 'node:diagnostics_channel';
|
2021-06-15 10:09:29 -07:00
|
|
|
|
|
|
|
// Get a reusable channel object
|
|
|
|
const channel = diagnostics_channel.channel('my-channel');
|
|
|
|
|
2022-04-12 15:54:03 -07:00
|
|
|
function onMessage(message, name) {
|
2021-06-15 10:09:29 -07:00
|
|
|
// Received data
|
2022-04-12 15:54:03 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
// Subscribe to the channel
|
|
|
|
diagnostics_channel.subscribe('my-channel', onMessage);
|
2021-06-15 10:09:29 -07:00
|
|
|
|
|
|
|
// Check if the channel has an active subscriber
|
|
|
|
if (channel.hasSubscribers) {
|
|
|
|
// Publish data to the channel
|
|
|
|
channel.publish({
|
2022-11-17 08:19:12 -05:00
|
|
|
some: 'data',
|
2021-06-15 10:09:29 -07:00
|
|
|
});
|
|
|
|
}
|
2022-04-12 15:54:03 -07:00
|
|
|
|
|
|
|
// Unsubscribe from the channel
|
|
|
|
diagnostics_channel.unsubscribe('my-channel', onMessage);
|
2021-06-15 10:09:29 -07:00
|
|
|
```
|
|
|
|
|
|
|
|
```cjs
|
2022-04-20 10:23:41 +02:00
|
|
|
const diagnostics_channel = require('node:diagnostics_channel');
|
2020-08-21 16:25:39 -07:00
|
|
|
|
|
|
|
// Get a reusable channel object
|
|
|
|
const channel = diagnostics_channel.channel('my-channel');
|
|
|
|
|
2022-04-12 15:54:03 -07:00
|
|
|
function onMessage(message, name) {
|
2020-08-21 16:25:39 -07:00
|
|
|
// Received data
|
2022-04-12 15:54:03 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
// Subscribe to the channel
|
|
|
|
diagnostics_channel.subscribe('my-channel', onMessage);
|
2020-08-21 16:25:39 -07:00
|
|
|
|
|
|
|
// Check if the channel has an active subscriber
|
|
|
|
if (channel.hasSubscribers) {
|
|
|
|
// Publish data to the channel
|
|
|
|
channel.publish({
|
2022-11-17 08:19:12 -05:00
|
|
|
some: 'data',
|
2020-08-21 16:25:39 -07:00
|
|
|
});
|
|
|
|
}
|
2022-04-12 15:54:03 -07:00
|
|
|
|
|
|
|
// Unsubscribe from the channel
|
|
|
|
diagnostics_channel.unsubscribe('my-channel', onMessage);
|
2020-08-21 16:25:39 -07:00
|
|
|
```
|
|
|
|
|
|
|
|
#### `diagnostics_channel.hasSubscribers(name)`
|
|
|
|
|
2021-09-24 13:47:58 +02:00
|
|
|
<!-- YAML
|
|
|
|
added:
|
|
|
|
- v15.1.0
|
|
|
|
- v14.17.0
|
|
|
|
-->
|
|
|
|
|
2020-08-21 16:25:39 -07:00
|
|
|
* `name` {string|symbol} The channel name
|
|
|
|
* Returns: {boolean} If there are active subscribers
|
|
|
|
|
|
|
|
Check if there are active subscribers to the named channel. This is helpful if
|
|
|
|
the message you want to send might be expensive to prepare.
|
|
|
|
|
|
|
|
This API is optional but helpful when trying to publish messages from very
|
2021-02-11 18:46:45 +01:00
|
|
|
performance-sensitive code.
|
2020-08-21 16:25:39 -07:00
|
|
|
|
2021-06-15 10:09:29 -07:00
|
|
|
```mjs
|
2022-04-20 10:23:41 +02:00
|
|
|
import diagnostics_channel from 'node:diagnostics_channel';
|
2021-06-15 10:09:29 -07:00
|
|
|
|
|
|
|
if (diagnostics_channel.hasSubscribers('my-channel')) {
|
|
|
|
// There are subscribers, prepare and publish message
|
|
|
|
}
|
|
|
|
```
|
|
|
|
|
|
|
|
```cjs
|
2022-04-20 10:23:41 +02:00
|
|
|
const diagnostics_channel = require('node:diagnostics_channel');
|
2020-08-21 16:25:39 -07:00
|
|
|
|
|
|
|
if (diagnostics_channel.hasSubscribers('my-channel')) {
|
|
|
|
// There are subscribers, prepare and publish message
|
|
|
|
}
|
|
|
|
```
|
|
|
|
|
|
|
|
#### `diagnostics_channel.channel(name)`
|
|
|
|
|
2021-09-24 13:47:58 +02:00
|
|
|
<!-- YAML
|
|
|
|
added:
|
|
|
|
- v15.1.0
|
|
|
|
- v14.17.0
|
|
|
|
-->
|
|
|
|
|
2020-08-21 16:25:39 -07:00
|
|
|
* `name` {string|symbol} The channel name
|
|
|
|
* Returns: {Channel} The named channel object
|
|
|
|
|
2022-04-12 15:54:03 -07:00
|
|
|
This is the primary entry-point for anyone wanting to publish to a named
|
2020-08-21 16:25:39 -07:00
|
|
|
channel. It produces a channel object which is optimized to reduce overhead at
|
|
|
|
publish time as much as possible.
|
|
|
|
|
2021-06-15 10:09:29 -07:00
|
|
|
```mjs
|
2022-04-20 10:23:41 +02:00
|
|
|
import diagnostics_channel from 'node:diagnostics_channel';
|
2021-06-15 10:09:29 -07:00
|
|
|
|
|
|
|
const channel = diagnostics_channel.channel('my-channel');
|
|
|
|
```
|
|
|
|
|
|
|
|
```cjs
|
2022-04-20 10:23:41 +02:00
|
|
|
const diagnostics_channel = require('node:diagnostics_channel');
|
2020-08-21 16:25:39 -07:00
|
|
|
|
|
|
|
const channel = diagnostics_channel.channel('my-channel');
|
|
|
|
```
|
|
|
|
|
2022-04-12 15:54:03 -07:00
|
|
|
#### `diagnostics_channel.subscribe(name, onMessage)`
|
|
|
|
|
|
|
|
<!-- YAML
|
|
|
|
added:
|
2022-07-25 22:32:16 -04:00
|
|
|
- v18.7.0
|
2022-08-16, Version 16.17.0 'Gallium' (LTS)
Notable changes:
Adds `util.parseArgs` helper for higher level command-line argument
parsing.
Contributed by Benjamin Coe, John Gee, Darcy Clarke, Joe Sepi,
Kevin Gibbons, Aaron Casanova, Jessica Nahulan, and Jordan Harband.
https://github.com/nodejs/node/pull/42675
Node.js ESM Loader hooks now support multiple custom loaders, and
composition is achieved via "chaining": `foo-loader` calls `bar-loader`
calls `qux-loader` (a custom loader _must_ now signal a short circuit
when intentionally not calling the next). See the ESM docs
(https://nodejs.org/dist/latest-v16.x/docs/api/esm.html) for details.
Contributed by Jacob Smith, Geoffrey Booth, and Bradley Farias.
https://github.com/nodejs/node/pull/42623
The `node:test` module, which was initially introduced in Node.js
v18.0.0, is now available with all the changes done to it up to Node.js
v18.7.0.
To better align Node.js' experimental implementation of the Web Crypto
API with other runtimes, several changes were made:
* Support for CFRG curves was added, with the `'Ed25519'`, `'Ed448'`,
`'X25519'`, and `'X448'` algorithms.
* The proprietary `'NODE-DSA'`, `'NODE-DH'`, `'NODE-SCRYPT'`,
`'NODE-ED25519'`, `'NODE-ED448'`, `'NODE-X25519'`, and `'NODE-X448'`
algorithms were removed.
* The proprietary `'node.keyObject'` import/export format was removed.
Contributed by Filip Skokan.
https://github.com/nodejs/node/pull/42507
https://github.com/nodejs/node/pull/43310
Updated Corepack to 0.12.1 - https://github.com/nodejs/node/pull/43965
Updated ICU to 71.1 - https://github.com/nodejs/node/pull/42655
Updated npm to 8.15.0 - https://github.com/nodejs/node/pull/43917
Updated Undici to 5.8.0 - https://github.com/nodejs/node/pull/43886
(SEMVER-MINOR) crypto: make authTagLength optional for CC20P1305 (Tobias Nießen) https://github.com/nodejs/node/pull/42427
(SEMVER-MINOR) crypto: align webcrypto RSA key import/export with other implementations (Filip Skokan) https://github.com/nodejs/node/pull/42816
(SEMVER-MINOR) dns: export error code constants from `dns/promises` (Feng Yu) https://github.com/nodejs/node/pull/43176
doc: deprecate coercion to integer in process.exit (Daeyeon Jeong) https://github.com/nodejs/node/pull/43738
(SEMVER-MINOR) doc: deprecate diagnostics_channel object subscribe method (Stephen Belanger) https://github.com/nodejs/node/pull/42714
(SEMVER-MINOR) errors: add support for cause in aborterror (James M Snell) https://github.com/nodejs/node/pull/41008
(SEMVER-MINOR) events: expose CustomEvent on global with CLI flag (Daeyeon Jeong) https://github.com/nodejs/node/pull/43885
(SEMVER-MINOR) events: add `CustomEvent` (Daeyeon Jeong) https://github.com/nodejs/node/pull/43514
(SEMVER-MINOR) events: propagate abortsignal reason in new AbortError ctor in events (James M Snell) https://github.com/nodejs/node/pull/41008
(SEMVER-MINOR) fs: propagate abortsignal reason in new AbortSignal constructors (James M Snell) https://github.com/nodejs/node/pull/41008
(SEMVER-MINOR) fs: make params in writing methods optional (LiviaMedeiros) https://github.com/nodejs/node/pull/42601
(SEMVER-MINOR) fs: add `read(buffer[, options])` versions (LiviaMedeiros) https://github.com/nodejs/node/pull/42768
(SEMVER-MINOR) http: add drop request event for http server (theanarkh) https://github.com/nodejs/node/pull/43806
(SEMVER-MINOR) http: add diagnostics channel for http client (theanarkh) https://github.com/nodejs/node/pull/43580
(SEMVER-MINOR) http: add perf_hooks detail for http request and client (theanarkh) https://github.com/nodejs/node/pull/43361
(SEMVER-MINOR) http: add uniqueHeaders option to request and createServer (Paolo Insogna) https://github.com/nodejs/node/pull/41397
(SEMVER-MINOR) http2: propagate abortsignal reason in new AbortError constructor (James M Snell) https://github.com/nodejs/node/pull/41008
(SEMVER-MINOR) http2: compat support for array headers (OneNail) https://github.com/nodejs/node/pull/42901
(SEMVER-MINOR) lib: propagate abortsignal reason in new AbortError constructor in blob (James M Snell) https://github.com/nodejs/node/pull/41008
(SEMVER-MINOR) lib: add abortSignal.throwIfAborted() (James M Snell) https://github.com/nodejs/node/pull/40951
(SEMVER-MINOR) lib: improved diagnostics_channel subscribe/unsubscribe (Stephen Belanger) https://github.com/nodejs/node/pull/42714
(SEMVER-MINOR) module: add isBuiltIn method (hemanth.hm) https://github.com/nodejs/node/pull/43396
(SEMVER-MINOR) module,repl: support 'node:'-only core modules (Colin Ihrig) https://github.com/nodejs/node/pull/42325
(SEMVER-MINOR) net: add drop event for net server (theanarkh) https://github.com/nodejs/node/pull/43582
(SEMVER-MINOR) net: add ability to reset a tcp socket (pupilTong) https://github.com/nodejs/node/pull/43112
(SEMVER-MINOR) node-api: emit uncaught-exception on unhandled tsfn callbacks (Chengzhong Wu) https://github.com/nodejs/node/pull/36510
(SEMVER-MINOR) perf_hooks: add PerformanceResourceTiming (RafaelGSS) https://github.com/nodejs/node/pull/42725
(SEMVER-MINOR) report: add more heap infos in process report (theanarkh) https://github.com/nodejs/node/pull/43116
(SEMVER-MINOR) src: add --openssl-legacy-provider option (Daniel Bevenius) https://github.com/nodejs/node/pull/40478
(SEMVER-MINOR) src: define fs.constants.S_IWUSR & S_IRUSR for Win (Liviu Ionescu) https://github.com/nodejs/node/pull/42757
(SEMVER-MINOR) src,doc,test: add --openssl-shared-config option (Daniel Bevenius) https://github.com/nodejs/node/pull/43124
(SEMVER-MINOR) stream: use cause options in AbortError constructors (James M Snell) https://github.com/nodejs/node/pull/41008
(SEMVER-MINOR) stream: add iterator helper find (Nitzan Uziely) https://github.com/nodejs/node/pull/41849
(SEMVER-MINOR) stream: add writableAborted (Robert Nagy) https://github.com/nodejs/node/pull/40802
(SEMVER-MINOR) timers: propagate signal.reason in awaitable timers (James M Snell) https://github.com/nodejs/node/pull/41008
(SEMVER-MINOR) v8: add v8.startupSnapshot utils (Joyee Cheung) https://github.com/nodejs/node/pull/43329
(SEMVER-MINOR) v8: export more fields in getHeapStatistics (theanarkh) https://github.com/nodejs/node/pull/42784
(SEMVER-MINOR) worker: add hasRef() to MessagePort (Darshan Sen) https://github.com/nodejs/node/pull/42849
PR-URL: https://github.com/nodejs/node/pull/44098
2022-08-02 14:34:18 +02:00
|
|
|
- v16.17.0
|
2022-04-12 15:54:03 -07:00
|
|
|
-->
|
|
|
|
|
|
|
|
* `name` {string|symbol} The channel name
|
|
|
|
* `onMessage` {Function} The handler to receive channel messages
|
|
|
|
* `message` {any} The message data
|
|
|
|
* `name` {string|symbol} The name of the channel
|
|
|
|
|
|
|
|
Register a message handler to subscribe to this channel. This message handler
|
|
|
|
will be run synchronously whenever a message is published to the channel. Any
|
|
|
|
errors thrown in the message handler will trigger an [`'uncaughtException'`][].
|
|
|
|
|
|
|
|
```mjs
|
2022-11-06 06:53:23 +09:00
|
|
|
import diagnostics_channel from 'node:diagnostics_channel';
|
2022-04-12 15:54:03 -07:00
|
|
|
|
|
|
|
diagnostics_channel.subscribe('my-channel', (message, name) => {
|
|
|
|
// Received data
|
|
|
|
});
|
|
|
|
```
|
|
|
|
|
|
|
|
```cjs
|
2022-11-06 06:53:23 +09:00
|
|
|
const diagnostics_channel = require('node:diagnostics_channel');
|
2022-04-12 15:54:03 -07:00
|
|
|
|
|
|
|
diagnostics_channel.subscribe('my-channel', (message, name) => {
|
|
|
|
// Received data
|
|
|
|
});
|
|
|
|
```
|
|
|
|
|
|
|
|
#### `diagnostics_channel.unsubscribe(name, onMessage)`
|
|
|
|
|
|
|
|
<!-- YAML
|
|
|
|
added:
|
2022-07-25 22:32:16 -04:00
|
|
|
- v18.7.0
|
2022-08-16, Version 16.17.0 'Gallium' (LTS)
Notable changes:
Adds `util.parseArgs` helper for higher level command-line argument
parsing.
Contributed by Benjamin Coe, John Gee, Darcy Clarke, Joe Sepi,
Kevin Gibbons, Aaron Casanova, Jessica Nahulan, and Jordan Harband.
https://github.com/nodejs/node/pull/42675
Node.js ESM Loader hooks now support multiple custom loaders, and
composition is achieved via "chaining": `foo-loader` calls `bar-loader`
calls `qux-loader` (a custom loader _must_ now signal a short circuit
when intentionally not calling the next). See the ESM docs
(https://nodejs.org/dist/latest-v16.x/docs/api/esm.html) for details.
Contributed by Jacob Smith, Geoffrey Booth, and Bradley Farias.
https://github.com/nodejs/node/pull/42623
The `node:test` module, which was initially introduced in Node.js
v18.0.0, is now available with all the changes done to it up to Node.js
v18.7.0.
To better align Node.js' experimental implementation of the Web Crypto
API with other runtimes, several changes were made:
* Support for CFRG curves was added, with the `'Ed25519'`, `'Ed448'`,
`'X25519'`, and `'X448'` algorithms.
* The proprietary `'NODE-DSA'`, `'NODE-DH'`, `'NODE-SCRYPT'`,
`'NODE-ED25519'`, `'NODE-ED448'`, `'NODE-X25519'`, and `'NODE-X448'`
algorithms were removed.
* The proprietary `'node.keyObject'` import/export format was removed.
Contributed by Filip Skokan.
https://github.com/nodejs/node/pull/42507
https://github.com/nodejs/node/pull/43310
Updated Corepack to 0.12.1 - https://github.com/nodejs/node/pull/43965
Updated ICU to 71.1 - https://github.com/nodejs/node/pull/42655
Updated npm to 8.15.0 - https://github.com/nodejs/node/pull/43917
Updated Undici to 5.8.0 - https://github.com/nodejs/node/pull/43886
(SEMVER-MINOR) crypto: make authTagLength optional for CC20P1305 (Tobias Nießen) https://github.com/nodejs/node/pull/42427
(SEMVER-MINOR) crypto: align webcrypto RSA key import/export with other implementations (Filip Skokan) https://github.com/nodejs/node/pull/42816
(SEMVER-MINOR) dns: export error code constants from `dns/promises` (Feng Yu) https://github.com/nodejs/node/pull/43176
doc: deprecate coercion to integer in process.exit (Daeyeon Jeong) https://github.com/nodejs/node/pull/43738
(SEMVER-MINOR) doc: deprecate diagnostics_channel object subscribe method (Stephen Belanger) https://github.com/nodejs/node/pull/42714
(SEMVER-MINOR) errors: add support for cause in aborterror (James M Snell) https://github.com/nodejs/node/pull/41008
(SEMVER-MINOR) events: expose CustomEvent on global with CLI flag (Daeyeon Jeong) https://github.com/nodejs/node/pull/43885
(SEMVER-MINOR) events: add `CustomEvent` (Daeyeon Jeong) https://github.com/nodejs/node/pull/43514
(SEMVER-MINOR) events: propagate abortsignal reason in new AbortError ctor in events (James M Snell) https://github.com/nodejs/node/pull/41008
(SEMVER-MINOR) fs: propagate abortsignal reason in new AbortSignal constructors (James M Snell) https://github.com/nodejs/node/pull/41008
(SEMVER-MINOR) fs: make params in writing methods optional (LiviaMedeiros) https://github.com/nodejs/node/pull/42601
(SEMVER-MINOR) fs: add `read(buffer[, options])` versions (LiviaMedeiros) https://github.com/nodejs/node/pull/42768
(SEMVER-MINOR) http: add drop request event for http server (theanarkh) https://github.com/nodejs/node/pull/43806
(SEMVER-MINOR) http: add diagnostics channel for http client (theanarkh) https://github.com/nodejs/node/pull/43580
(SEMVER-MINOR) http: add perf_hooks detail for http request and client (theanarkh) https://github.com/nodejs/node/pull/43361
(SEMVER-MINOR) http: add uniqueHeaders option to request and createServer (Paolo Insogna) https://github.com/nodejs/node/pull/41397
(SEMVER-MINOR) http2: propagate abortsignal reason in new AbortError constructor (James M Snell) https://github.com/nodejs/node/pull/41008
(SEMVER-MINOR) http2: compat support for array headers (OneNail) https://github.com/nodejs/node/pull/42901
(SEMVER-MINOR) lib: propagate abortsignal reason in new AbortError constructor in blob (James M Snell) https://github.com/nodejs/node/pull/41008
(SEMVER-MINOR) lib: add abortSignal.throwIfAborted() (James M Snell) https://github.com/nodejs/node/pull/40951
(SEMVER-MINOR) lib: improved diagnostics_channel subscribe/unsubscribe (Stephen Belanger) https://github.com/nodejs/node/pull/42714
(SEMVER-MINOR) module: add isBuiltIn method (hemanth.hm) https://github.com/nodejs/node/pull/43396
(SEMVER-MINOR) module,repl: support 'node:'-only core modules (Colin Ihrig) https://github.com/nodejs/node/pull/42325
(SEMVER-MINOR) net: add drop event for net server (theanarkh) https://github.com/nodejs/node/pull/43582
(SEMVER-MINOR) net: add ability to reset a tcp socket (pupilTong) https://github.com/nodejs/node/pull/43112
(SEMVER-MINOR) node-api: emit uncaught-exception on unhandled tsfn callbacks (Chengzhong Wu) https://github.com/nodejs/node/pull/36510
(SEMVER-MINOR) perf_hooks: add PerformanceResourceTiming (RafaelGSS) https://github.com/nodejs/node/pull/42725
(SEMVER-MINOR) report: add more heap infos in process report (theanarkh) https://github.com/nodejs/node/pull/43116
(SEMVER-MINOR) src: add --openssl-legacy-provider option (Daniel Bevenius) https://github.com/nodejs/node/pull/40478
(SEMVER-MINOR) src: define fs.constants.S_IWUSR & S_IRUSR for Win (Liviu Ionescu) https://github.com/nodejs/node/pull/42757
(SEMVER-MINOR) src,doc,test: add --openssl-shared-config option (Daniel Bevenius) https://github.com/nodejs/node/pull/43124
(SEMVER-MINOR) stream: use cause options in AbortError constructors (James M Snell) https://github.com/nodejs/node/pull/41008
(SEMVER-MINOR) stream: add iterator helper find (Nitzan Uziely) https://github.com/nodejs/node/pull/41849
(SEMVER-MINOR) stream: add writableAborted (Robert Nagy) https://github.com/nodejs/node/pull/40802
(SEMVER-MINOR) timers: propagate signal.reason in awaitable timers (James M Snell) https://github.com/nodejs/node/pull/41008
(SEMVER-MINOR) v8: add v8.startupSnapshot utils (Joyee Cheung) https://github.com/nodejs/node/pull/43329
(SEMVER-MINOR) v8: export more fields in getHeapStatistics (theanarkh) https://github.com/nodejs/node/pull/42784
(SEMVER-MINOR) worker: add hasRef() to MessagePort (Darshan Sen) https://github.com/nodejs/node/pull/42849
PR-URL: https://github.com/nodejs/node/pull/44098
2022-08-02 14:34:18 +02:00
|
|
|
- v16.17.0
|
2022-04-12 15:54:03 -07:00
|
|
|
-->
|
|
|
|
|
|
|
|
* `name` {string|symbol} The channel name
|
|
|
|
* `onMessage` {Function} The previous subscribed handler to remove
|
|
|
|
* Returns: {boolean} `true` if the handler was found, `false` otherwise.
|
|
|
|
|
|
|
|
Remove a message handler previously registered to this channel with
|
|
|
|
[`diagnostics_channel.subscribe(name, onMessage)`][].
|
|
|
|
|
|
|
|
```mjs
|
2022-11-06 06:53:23 +09:00
|
|
|
import diagnostics_channel from 'node:diagnostics_channel';
|
2022-04-12 15:54:03 -07:00
|
|
|
|
|
|
|
function onMessage(message, name) {
|
|
|
|
// Received data
|
|
|
|
}
|
|
|
|
|
|
|
|
diagnostics_channel.subscribe('my-channel', onMessage);
|
|
|
|
|
|
|
|
diagnostics_channel.unsubscribe('my-channel', onMessage);
|
|
|
|
```
|
|
|
|
|
|
|
|
```cjs
|
2022-11-06 06:53:23 +09:00
|
|
|
const diagnostics_channel = require('node:diagnostics_channel');
|
2022-04-12 15:54:03 -07:00
|
|
|
|
|
|
|
function onMessage(message, name) {
|
|
|
|
// Received data
|
|
|
|
}
|
|
|
|
|
|
|
|
diagnostics_channel.subscribe('my-channel', onMessage);
|
|
|
|
|
|
|
|
diagnostics_channel.unsubscribe('my-channel', onMessage);
|
|
|
|
```
|
|
|
|
|
2020-08-21 16:25:39 -07:00
|
|
|
### Class: `Channel`
|
|
|
|
|
2021-09-24 13:47:58 +02:00
|
|
|
<!-- YAML
|
|
|
|
added:
|
|
|
|
- v15.1.0
|
|
|
|
- v14.17.0
|
|
|
|
-->
|
|
|
|
|
2020-08-21 16:25:39 -07:00
|
|
|
The class `Channel` represents an individual named channel within the data
|
2022-08-10 10:47:59 -05:00
|
|
|
pipeline. It is used to track subscribers and to publish messages when there
|
2020-08-21 16:25:39 -07:00
|
|
|
are subscribers present. It exists as a separate object to avoid channel
|
|
|
|
lookups at publish time, enabling very fast publish speeds and allowing
|
|
|
|
for heavy use while incurring very minimal cost. Channels are created with
|
|
|
|
[`diagnostics_channel.channel(name)`][], constructing a channel directly
|
|
|
|
with `new Channel(name)` is not supported.
|
|
|
|
|
|
|
|
#### `channel.hasSubscribers`
|
|
|
|
|
2021-09-24 13:47:58 +02:00
|
|
|
<!-- YAML
|
|
|
|
added:
|
|
|
|
- v15.1.0
|
|
|
|
- v14.17.0
|
|
|
|
-->
|
|
|
|
|
2020-08-21 16:25:39 -07:00
|
|
|
* Returns: {boolean} If there are active subscribers
|
|
|
|
|
|
|
|
Check if there are active subscribers to this channel. This is helpful if
|
|
|
|
the message you want to send might be expensive to prepare.
|
|
|
|
|
|
|
|
This API is optional but helpful when trying to publish messages from very
|
2021-02-11 18:46:45 +01:00
|
|
|
performance-sensitive code.
|
2020-08-21 16:25:39 -07:00
|
|
|
|
2021-06-15 10:09:29 -07:00
|
|
|
```mjs
|
2022-04-20 10:23:41 +02:00
|
|
|
import diagnostics_channel from 'node:diagnostics_channel';
|
2021-06-15 10:09:29 -07:00
|
|
|
|
|
|
|
const channel = diagnostics_channel.channel('my-channel');
|
|
|
|
|
|
|
|
if (channel.hasSubscribers) {
|
|
|
|
// There are subscribers, prepare and publish message
|
|
|
|
}
|
|
|
|
```
|
|
|
|
|
|
|
|
```cjs
|
2022-04-20 10:23:41 +02:00
|
|
|
const diagnostics_channel = require('node:diagnostics_channel');
|
2020-08-21 16:25:39 -07:00
|
|
|
|
|
|
|
const channel = diagnostics_channel.channel('my-channel');
|
|
|
|
|
|
|
|
if (channel.hasSubscribers) {
|
|
|
|
// There are subscribers, prepare and publish message
|
|
|
|
}
|
|
|
|
```
|
|
|
|
|
|
|
|
#### `channel.publish(message)`
|
|
|
|
|
2021-09-24 13:47:58 +02:00
|
|
|
<!-- YAML
|
|
|
|
added:
|
|
|
|
- v15.1.0
|
|
|
|
- v14.17.0
|
|
|
|
-->
|
|
|
|
|
2020-08-21 16:25:39 -07:00
|
|
|
* `message` {any} The message to send to the channel subscribers
|
|
|
|
|
|
|
|
Publish a message to any subscribers to the channel. This will trigger
|
|
|
|
message handlers synchronously so they will execute within the same context.
|
|
|
|
|
2021-06-15 10:09:29 -07:00
|
|
|
```mjs
|
2022-04-20 10:23:41 +02:00
|
|
|
import diagnostics_channel from 'node:diagnostics_channel';
|
2021-06-15 10:09:29 -07:00
|
|
|
|
|
|
|
const channel = diagnostics_channel.channel('my-channel');
|
|
|
|
|
|
|
|
channel.publish({
|
2022-11-17 08:19:12 -05:00
|
|
|
some: 'message',
|
2021-06-15 10:09:29 -07:00
|
|
|
});
|
|
|
|
```
|
|
|
|
|
|
|
|
```cjs
|
2022-04-20 10:23:41 +02:00
|
|
|
const diagnostics_channel = require('node:diagnostics_channel');
|
2020-08-21 16:25:39 -07:00
|
|
|
|
|
|
|
const channel = diagnostics_channel.channel('my-channel');
|
|
|
|
|
|
|
|
channel.publish({
|
2022-11-17 08:19:12 -05:00
|
|
|
some: 'message',
|
2020-08-21 16:25:39 -07:00
|
|
|
});
|
|
|
|
```
|
|
|
|
|
|
|
|
#### `channel.subscribe(onMessage)`
|
|
|
|
|
2021-09-24 13:47:58 +02:00
|
|
|
<!-- YAML
|
|
|
|
added:
|
|
|
|
- v15.1.0
|
|
|
|
- v14.17.0
|
2022-08-16, Version 16.17.0 'Gallium' (LTS)
Notable changes:
Adds `util.parseArgs` helper for higher level command-line argument
parsing.
Contributed by Benjamin Coe, John Gee, Darcy Clarke, Joe Sepi,
Kevin Gibbons, Aaron Casanova, Jessica Nahulan, and Jordan Harband.
https://github.com/nodejs/node/pull/42675
Node.js ESM Loader hooks now support multiple custom loaders, and
composition is achieved via "chaining": `foo-loader` calls `bar-loader`
calls `qux-loader` (a custom loader _must_ now signal a short circuit
when intentionally not calling the next). See the ESM docs
(https://nodejs.org/dist/latest-v16.x/docs/api/esm.html) for details.
Contributed by Jacob Smith, Geoffrey Booth, and Bradley Farias.
https://github.com/nodejs/node/pull/42623
The `node:test` module, which was initially introduced in Node.js
v18.0.0, is now available with all the changes done to it up to Node.js
v18.7.0.
To better align Node.js' experimental implementation of the Web Crypto
API with other runtimes, several changes were made:
* Support for CFRG curves was added, with the `'Ed25519'`, `'Ed448'`,
`'X25519'`, and `'X448'` algorithms.
* The proprietary `'NODE-DSA'`, `'NODE-DH'`, `'NODE-SCRYPT'`,
`'NODE-ED25519'`, `'NODE-ED448'`, `'NODE-X25519'`, and `'NODE-X448'`
algorithms were removed.
* The proprietary `'node.keyObject'` import/export format was removed.
Contributed by Filip Skokan.
https://github.com/nodejs/node/pull/42507
https://github.com/nodejs/node/pull/43310
Updated Corepack to 0.12.1 - https://github.com/nodejs/node/pull/43965
Updated ICU to 71.1 - https://github.com/nodejs/node/pull/42655
Updated npm to 8.15.0 - https://github.com/nodejs/node/pull/43917
Updated Undici to 5.8.0 - https://github.com/nodejs/node/pull/43886
(SEMVER-MINOR) crypto: make authTagLength optional for CC20P1305 (Tobias Nießen) https://github.com/nodejs/node/pull/42427
(SEMVER-MINOR) crypto: align webcrypto RSA key import/export with other implementations (Filip Skokan) https://github.com/nodejs/node/pull/42816
(SEMVER-MINOR) dns: export error code constants from `dns/promises` (Feng Yu) https://github.com/nodejs/node/pull/43176
doc: deprecate coercion to integer in process.exit (Daeyeon Jeong) https://github.com/nodejs/node/pull/43738
(SEMVER-MINOR) doc: deprecate diagnostics_channel object subscribe method (Stephen Belanger) https://github.com/nodejs/node/pull/42714
(SEMVER-MINOR) errors: add support for cause in aborterror (James M Snell) https://github.com/nodejs/node/pull/41008
(SEMVER-MINOR) events: expose CustomEvent on global with CLI flag (Daeyeon Jeong) https://github.com/nodejs/node/pull/43885
(SEMVER-MINOR) events: add `CustomEvent` (Daeyeon Jeong) https://github.com/nodejs/node/pull/43514
(SEMVER-MINOR) events: propagate abortsignal reason in new AbortError ctor in events (James M Snell) https://github.com/nodejs/node/pull/41008
(SEMVER-MINOR) fs: propagate abortsignal reason in new AbortSignal constructors (James M Snell) https://github.com/nodejs/node/pull/41008
(SEMVER-MINOR) fs: make params in writing methods optional (LiviaMedeiros) https://github.com/nodejs/node/pull/42601
(SEMVER-MINOR) fs: add `read(buffer[, options])` versions (LiviaMedeiros) https://github.com/nodejs/node/pull/42768
(SEMVER-MINOR) http: add drop request event for http server (theanarkh) https://github.com/nodejs/node/pull/43806
(SEMVER-MINOR) http: add diagnostics channel for http client (theanarkh) https://github.com/nodejs/node/pull/43580
(SEMVER-MINOR) http: add perf_hooks detail for http request and client (theanarkh) https://github.com/nodejs/node/pull/43361
(SEMVER-MINOR) http: add uniqueHeaders option to request and createServer (Paolo Insogna) https://github.com/nodejs/node/pull/41397
(SEMVER-MINOR) http2: propagate abortsignal reason in new AbortError constructor (James M Snell) https://github.com/nodejs/node/pull/41008
(SEMVER-MINOR) http2: compat support for array headers (OneNail) https://github.com/nodejs/node/pull/42901
(SEMVER-MINOR) lib: propagate abortsignal reason in new AbortError constructor in blob (James M Snell) https://github.com/nodejs/node/pull/41008
(SEMVER-MINOR) lib: add abortSignal.throwIfAborted() (James M Snell) https://github.com/nodejs/node/pull/40951
(SEMVER-MINOR) lib: improved diagnostics_channel subscribe/unsubscribe (Stephen Belanger) https://github.com/nodejs/node/pull/42714
(SEMVER-MINOR) module: add isBuiltIn method (hemanth.hm) https://github.com/nodejs/node/pull/43396
(SEMVER-MINOR) module,repl: support 'node:'-only core modules (Colin Ihrig) https://github.com/nodejs/node/pull/42325
(SEMVER-MINOR) net: add drop event for net server (theanarkh) https://github.com/nodejs/node/pull/43582
(SEMVER-MINOR) net: add ability to reset a tcp socket (pupilTong) https://github.com/nodejs/node/pull/43112
(SEMVER-MINOR) node-api: emit uncaught-exception on unhandled tsfn callbacks (Chengzhong Wu) https://github.com/nodejs/node/pull/36510
(SEMVER-MINOR) perf_hooks: add PerformanceResourceTiming (RafaelGSS) https://github.com/nodejs/node/pull/42725
(SEMVER-MINOR) report: add more heap infos in process report (theanarkh) https://github.com/nodejs/node/pull/43116
(SEMVER-MINOR) src: add --openssl-legacy-provider option (Daniel Bevenius) https://github.com/nodejs/node/pull/40478
(SEMVER-MINOR) src: define fs.constants.S_IWUSR & S_IRUSR for Win (Liviu Ionescu) https://github.com/nodejs/node/pull/42757
(SEMVER-MINOR) src,doc,test: add --openssl-shared-config option (Daniel Bevenius) https://github.com/nodejs/node/pull/43124
(SEMVER-MINOR) stream: use cause options in AbortError constructors (James M Snell) https://github.com/nodejs/node/pull/41008
(SEMVER-MINOR) stream: add iterator helper find (Nitzan Uziely) https://github.com/nodejs/node/pull/41849
(SEMVER-MINOR) stream: add writableAborted (Robert Nagy) https://github.com/nodejs/node/pull/40802
(SEMVER-MINOR) timers: propagate signal.reason in awaitable timers (James M Snell) https://github.com/nodejs/node/pull/41008
(SEMVER-MINOR) v8: add v8.startupSnapshot utils (Joyee Cheung) https://github.com/nodejs/node/pull/43329
(SEMVER-MINOR) v8: export more fields in getHeapStatistics (theanarkh) https://github.com/nodejs/node/pull/42784
(SEMVER-MINOR) worker: add hasRef() to MessagePort (Darshan Sen) https://github.com/nodejs/node/pull/42849
PR-URL: https://github.com/nodejs/node/pull/44098
2022-08-02 14:34:18 +02:00
|
|
|
deprecated:
|
|
|
|
- v18.7.0
|
|
|
|
- v16.17.0
|
2021-09-24 13:47:58 +02:00
|
|
|
-->
|
|
|
|
|
2022-05-31 10:52:09 -07:00
|
|
|
> Stability: 0 - Deprecated: Use [`diagnostics_channel.subscribe(name, onMessage)`][]
|
|
|
|
|
2020-08-21 16:25:39 -07:00
|
|
|
* `onMessage` {Function} The handler to receive channel messages
|
|
|
|
* `message` {any} The message data
|
|
|
|
* `name` {string|symbol} The name of the channel
|
|
|
|
|
|
|
|
Register a message handler to subscribe to this channel. This message handler
|
|
|
|
will be run synchronously whenever a message is published to the channel. Any
|
|
|
|
errors thrown in the message handler will trigger an [`'uncaughtException'`][].
|
|
|
|
|
2021-06-15 10:09:29 -07:00
|
|
|
```mjs
|
2022-04-20 10:23:41 +02:00
|
|
|
import diagnostics_channel from 'node:diagnostics_channel';
|
2021-06-15 10:09:29 -07:00
|
|
|
|
|
|
|
const channel = diagnostics_channel.channel('my-channel');
|
|
|
|
|
|
|
|
channel.subscribe((message, name) => {
|
|
|
|
// Received data
|
|
|
|
});
|
|
|
|
```
|
|
|
|
|
|
|
|
```cjs
|
2022-04-20 10:23:41 +02:00
|
|
|
const diagnostics_channel = require('node:diagnostics_channel');
|
2020-08-21 16:25:39 -07:00
|
|
|
|
|
|
|
const channel = diagnostics_channel.channel('my-channel');
|
|
|
|
|
|
|
|
channel.subscribe((message, name) => {
|
|
|
|
// Received data
|
|
|
|
});
|
|
|
|
```
|
|
|
|
|
|
|
|
#### `channel.unsubscribe(onMessage)`
|
|
|
|
|
2021-09-24 13:47:58 +02:00
|
|
|
<!-- YAML
|
|
|
|
added:
|
|
|
|
- v15.1.0
|
|
|
|
- v14.17.0
|
2022-08-16, Version 16.17.0 'Gallium' (LTS)
Notable changes:
Adds `util.parseArgs` helper for higher level command-line argument
parsing.
Contributed by Benjamin Coe, John Gee, Darcy Clarke, Joe Sepi,
Kevin Gibbons, Aaron Casanova, Jessica Nahulan, and Jordan Harband.
https://github.com/nodejs/node/pull/42675
Node.js ESM Loader hooks now support multiple custom loaders, and
composition is achieved via "chaining": `foo-loader` calls `bar-loader`
calls `qux-loader` (a custom loader _must_ now signal a short circuit
when intentionally not calling the next). See the ESM docs
(https://nodejs.org/dist/latest-v16.x/docs/api/esm.html) for details.
Contributed by Jacob Smith, Geoffrey Booth, and Bradley Farias.
https://github.com/nodejs/node/pull/42623
The `node:test` module, which was initially introduced in Node.js
v18.0.0, is now available with all the changes done to it up to Node.js
v18.7.0.
To better align Node.js' experimental implementation of the Web Crypto
API with other runtimes, several changes were made:
* Support for CFRG curves was added, with the `'Ed25519'`, `'Ed448'`,
`'X25519'`, and `'X448'` algorithms.
* The proprietary `'NODE-DSA'`, `'NODE-DH'`, `'NODE-SCRYPT'`,
`'NODE-ED25519'`, `'NODE-ED448'`, `'NODE-X25519'`, and `'NODE-X448'`
algorithms were removed.
* The proprietary `'node.keyObject'` import/export format was removed.
Contributed by Filip Skokan.
https://github.com/nodejs/node/pull/42507
https://github.com/nodejs/node/pull/43310
Updated Corepack to 0.12.1 - https://github.com/nodejs/node/pull/43965
Updated ICU to 71.1 - https://github.com/nodejs/node/pull/42655
Updated npm to 8.15.0 - https://github.com/nodejs/node/pull/43917
Updated Undici to 5.8.0 - https://github.com/nodejs/node/pull/43886
(SEMVER-MINOR) crypto: make authTagLength optional for CC20P1305 (Tobias Nießen) https://github.com/nodejs/node/pull/42427
(SEMVER-MINOR) crypto: align webcrypto RSA key import/export with other implementations (Filip Skokan) https://github.com/nodejs/node/pull/42816
(SEMVER-MINOR) dns: export error code constants from `dns/promises` (Feng Yu) https://github.com/nodejs/node/pull/43176
doc: deprecate coercion to integer in process.exit (Daeyeon Jeong) https://github.com/nodejs/node/pull/43738
(SEMVER-MINOR) doc: deprecate diagnostics_channel object subscribe method (Stephen Belanger) https://github.com/nodejs/node/pull/42714
(SEMVER-MINOR) errors: add support for cause in aborterror (James M Snell) https://github.com/nodejs/node/pull/41008
(SEMVER-MINOR) events: expose CustomEvent on global with CLI flag (Daeyeon Jeong) https://github.com/nodejs/node/pull/43885
(SEMVER-MINOR) events: add `CustomEvent` (Daeyeon Jeong) https://github.com/nodejs/node/pull/43514
(SEMVER-MINOR) events: propagate abortsignal reason in new AbortError ctor in events (James M Snell) https://github.com/nodejs/node/pull/41008
(SEMVER-MINOR) fs: propagate abortsignal reason in new AbortSignal constructors (James M Snell) https://github.com/nodejs/node/pull/41008
(SEMVER-MINOR) fs: make params in writing methods optional (LiviaMedeiros) https://github.com/nodejs/node/pull/42601
(SEMVER-MINOR) fs: add `read(buffer[, options])` versions (LiviaMedeiros) https://github.com/nodejs/node/pull/42768
(SEMVER-MINOR) http: add drop request event for http server (theanarkh) https://github.com/nodejs/node/pull/43806
(SEMVER-MINOR) http: add diagnostics channel for http client (theanarkh) https://github.com/nodejs/node/pull/43580
(SEMVER-MINOR) http: add perf_hooks detail for http request and client (theanarkh) https://github.com/nodejs/node/pull/43361
(SEMVER-MINOR) http: add uniqueHeaders option to request and createServer (Paolo Insogna) https://github.com/nodejs/node/pull/41397
(SEMVER-MINOR) http2: propagate abortsignal reason in new AbortError constructor (James M Snell) https://github.com/nodejs/node/pull/41008
(SEMVER-MINOR) http2: compat support for array headers (OneNail) https://github.com/nodejs/node/pull/42901
(SEMVER-MINOR) lib: propagate abortsignal reason in new AbortError constructor in blob (James M Snell) https://github.com/nodejs/node/pull/41008
(SEMVER-MINOR) lib: add abortSignal.throwIfAborted() (James M Snell) https://github.com/nodejs/node/pull/40951
(SEMVER-MINOR) lib: improved diagnostics_channel subscribe/unsubscribe (Stephen Belanger) https://github.com/nodejs/node/pull/42714
(SEMVER-MINOR) module: add isBuiltIn method (hemanth.hm) https://github.com/nodejs/node/pull/43396
(SEMVER-MINOR) module,repl: support 'node:'-only core modules (Colin Ihrig) https://github.com/nodejs/node/pull/42325
(SEMVER-MINOR) net: add drop event for net server (theanarkh) https://github.com/nodejs/node/pull/43582
(SEMVER-MINOR) net: add ability to reset a tcp socket (pupilTong) https://github.com/nodejs/node/pull/43112
(SEMVER-MINOR) node-api: emit uncaught-exception on unhandled tsfn callbacks (Chengzhong Wu) https://github.com/nodejs/node/pull/36510
(SEMVER-MINOR) perf_hooks: add PerformanceResourceTiming (RafaelGSS) https://github.com/nodejs/node/pull/42725
(SEMVER-MINOR) report: add more heap infos in process report (theanarkh) https://github.com/nodejs/node/pull/43116
(SEMVER-MINOR) src: add --openssl-legacy-provider option (Daniel Bevenius) https://github.com/nodejs/node/pull/40478
(SEMVER-MINOR) src: define fs.constants.S_IWUSR & S_IRUSR for Win (Liviu Ionescu) https://github.com/nodejs/node/pull/42757
(SEMVER-MINOR) src,doc,test: add --openssl-shared-config option (Daniel Bevenius) https://github.com/nodejs/node/pull/43124
(SEMVER-MINOR) stream: use cause options in AbortError constructors (James M Snell) https://github.com/nodejs/node/pull/41008
(SEMVER-MINOR) stream: add iterator helper find (Nitzan Uziely) https://github.com/nodejs/node/pull/41849
(SEMVER-MINOR) stream: add writableAborted (Robert Nagy) https://github.com/nodejs/node/pull/40802
(SEMVER-MINOR) timers: propagate signal.reason in awaitable timers (James M Snell) https://github.com/nodejs/node/pull/41008
(SEMVER-MINOR) v8: add v8.startupSnapshot utils (Joyee Cheung) https://github.com/nodejs/node/pull/43329
(SEMVER-MINOR) v8: export more fields in getHeapStatistics (theanarkh) https://github.com/nodejs/node/pull/42784
(SEMVER-MINOR) worker: add hasRef() to MessagePort (Darshan Sen) https://github.com/nodejs/node/pull/42849
PR-URL: https://github.com/nodejs/node/pull/44098
2022-08-02 14:34:18 +02:00
|
|
|
deprecated:
|
|
|
|
- v18.7.0
|
|
|
|
- v16.17.0
|
2021-10-19 11:56:42 +02:00
|
|
|
changes:
|
2022-01-25 13:22:09 -05:00
|
|
|
- version:
|
|
|
|
- v17.1.0
|
2022-02-01 00:34:51 -05:00
|
|
|
- v16.14.0
|
2022-01-25 13:22:09 -05:00
|
|
|
- v14.19.0
|
2021-10-19 11:56:42 +02:00
|
|
|
pr-url: https://github.com/nodejs/node/pull/40433
|
2021-10-19 12:01:41 +02:00
|
|
|
description: Added return value. Added to channels without subscribers.
|
2021-09-24 13:47:58 +02:00
|
|
|
-->
|
|
|
|
|
2022-05-31 10:52:09 -07:00
|
|
|
> Stability: 0 - Deprecated: Use [`diagnostics_channel.unsubscribe(name, onMessage)`][]
|
|
|
|
|
2020-08-21 16:25:39 -07:00
|
|
|
* `onMessage` {Function} The previous subscribed handler to remove
|
2021-10-19 11:56:42 +02:00
|
|
|
* Returns: {boolean} `true` if the handler was found, `false` otherwise.
|
2020-08-21 16:25:39 -07:00
|
|
|
|
|
|
|
Remove a message handler previously registered to this channel with
|
|
|
|
[`channel.subscribe(onMessage)`][].
|
|
|
|
|
2021-06-15 10:09:29 -07:00
|
|
|
```mjs
|
2022-04-20 10:23:41 +02:00
|
|
|
import diagnostics_channel from 'node:diagnostics_channel';
|
2021-06-15 10:09:29 -07:00
|
|
|
|
|
|
|
const channel = diagnostics_channel.channel('my-channel');
|
|
|
|
|
|
|
|
function onMessage(message, name) {
|
|
|
|
// Received data
|
|
|
|
}
|
|
|
|
|
|
|
|
channel.subscribe(onMessage);
|
|
|
|
|
|
|
|
channel.unsubscribe(onMessage);
|
|
|
|
```
|
|
|
|
|
|
|
|
```cjs
|
2022-04-20 10:23:41 +02:00
|
|
|
const diagnostics_channel = require('node:diagnostics_channel');
|
2020-08-21 16:25:39 -07:00
|
|
|
|
|
|
|
const channel = diagnostics_channel.channel('my-channel');
|
|
|
|
|
|
|
|
function onMessage(message, name) {
|
|
|
|
// Received data
|
|
|
|
}
|
|
|
|
|
|
|
|
channel.subscribe(onMessage);
|
|
|
|
|
|
|
|
channel.unsubscribe(onMessage);
|
|
|
|
```
|
|
|
|
|
2022-07-10 20:50:24 +08:00
|
|
|
### Built-in Channels
|
|
|
|
|
2022-11-15 11:35:10 -08:00
|
|
|
> Stability: 1 - Experimental
|
|
|
|
|
|
|
|
While the diagnostics\_channel API is now considered stable, the built-in
|
|
|
|
channels currently available are not. Each channel must be declared stable
|
|
|
|
independently.
|
|
|
|
|
2022-07-10 20:50:24 +08:00
|
|
|
#### HTTP
|
|
|
|
|
|
|
|
`http.client.request.start`
|
|
|
|
|
|
|
|
* `request` {http.ClientRequest}
|
|
|
|
|
|
|
|
Emitted when client starts a request.
|
|
|
|
|
|
|
|
`http.client.response.finish`
|
|
|
|
|
|
|
|
* `request` {http.ClientRequest}
|
|
|
|
* `response` {http.IncomingMessage}
|
|
|
|
|
|
|
|
Emitted when client receives a response.
|
|
|
|
|
|
|
|
`http.server.request.start`
|
|
|
|
|
|
|
|
* `request` {http.IncomingMessage}
|
|
|
|
* `response` {http.ServerResponse}
|
|
|
|
* `socket` {net.Socket}
|
|
|
|
* `server` {http.Server}
|
|
|
|
|
|
|
|
Emitted when server receives a request.
|
|
|
|
|
|
|
|
`http.server.response.finish`
|
|
|
|
|
|
|
|
* `request` {http.IncomingMessage}
|
|
|
|
* `response` {http.ServerResponse}
|
|
|
|
* `socket` {net.Socket}
|
|
|
|
* `server` {http.Server}
|
|
|
|
|
|
|
|
Emitted when server sends a response.
|
|
|
|
|
2022-08-31 01:08:33 +08:00
|
|
|
#### NET
|
|
|
|
|
2022-07-29 21:27:16 +08:00
|
|
|
`net.client.socket`
|
|
|
|
|
|
|
|
* `socket` {net.Socket}
|
|
|
|
|
|
|
|
Emitted when a new TCP or pipe client socket is created.
|
|
|
|
|
|
|
|
`net.server.socket`
|
|
|
|
|
|
|
|
* `socket` {net.Socket}
|
|
|
|
|
|
|
|
Emitted when a new TCP or pipe connection is received.
|
|
|
|
|
2022-08-31 01:08:33 +08:00
|
|
|
#### UDP
|
|
|
|
|
2022-07-29 21:27:16 +08:00
|
|
|
`udp.socket`
|
|
|
|
|
|
|
|
* `socket` {dgram.Socket}
|
|
|
|
|
|
|
|
Emitted when a new UDP socket is created.
|
|
|
|
|
2022-08-31 01:08:33 +08:00
|
|
|
#### Process
|
|
|
|
|
|
|
|
<!-- YAML
|
2022-10-11 14:54:19 -05:00
|
|
|
added: v16.18.0
|
2022-08-31 01:08:33 +08:00
|
|
|
-->
|
|
|
|
|
|
|
|
`child_process`
|
|
|
|
|
|
|
|
* `process` {ChildProcess}
|
|
|
|
|
|
|
|
Emitted when a new process is created.
|
|
|
|
|
|
|
|
#### Worker Thread
|
|
|
|
|
|
|
|
<!-- YAML
|
2022-10-11 14:54:19 -05:00
|
|
|
added: v16.18.0
|
2022-08-31 01:08:33 +08:00
|
|
|
-->
|
|
|
|
|
|
|
|
`worker_threads`
|
|
|
|
|
|
|
|
* `worker` [`Worker`][]
|
|
|
|
|
|
|
|
Emitted when a new thread is created.
|
|
|
|
|
2021-07-04 20:39:17 -07:00
|
|
|
[`'uncaughtException'`]: process.md#event-uncaughtexception
|
2022-08-31 01:08:33 +08:00
|
|
|
[`Worker`]: worker_threads.md#class-worker
|
2021-07-04 20:39:17 -07:00
|
|
|
[`channel.subscribe(onMessage)`]: #channelsubscribeonmessage
|
|
|
|
[`diagnostics_channel.channel(name)`]: #diagnostics_channelchannelname
|
2022-05-31 10:52:09 -07:00
|
|
|
[`diagnostics_channel.subscribe(name, onMessage)`]: #diagnostics_channelsubscribename-onmessage
|
|
|
|
[`diagnostics_channel.unsubscribe(name, onMessage)`]: #diagnostics_channelunsubscribename-onmessage
|