Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit f336e61

Browse filesBrowse files
tlhuntermarco-ippolito
authored andcommitted
doc, test: tracing channel hasSubscribers getter
follow up work for #51915 PR-URL: #52908 Reviewed-By: Stephen Belanger <admin@stephenbelanger.com> Reviewed-By: James M Snell <jasnell@gmail.com>
1 parent 5eea419 commit f336e61
Copy full SHA for f336e61

2 files changed

+88Lines changed: 88 additions & 0 deletions

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎doc/api/diagnostics_channel.md‎

Copy file name to clipboardExpand all lines: doc/api/diagnostics_channel.md
+37Lines changed: 37 additions & 0 deletions
  • Display the source diff
  • Display the rich diff
Original file line numberDiff line numberDiff line change
@@ -967,6 +967,43 @@ channels.asyncStart.bindStore(myStore, (data) => {
967967
});
968968
```
969969

970+
#### `tracingChannel.hasSubscribers`
971+
972+
<!-- YAML
973+
added:
974+
- v22.0.0
975+
- v20.13.0
976+
-->
977+
978+
> Stability: 1 - Experimental
979+
980+
* Returns: {boolean} `true` if any of the individual channels has a subscriber,
981+
`false` if not.
982+
983+
This is a helper method available on a [`TracingChannel`][] instance to check if
984+
any of the [TracingChannel Channels][] have subscribers. A `true` is returned if
985+
any of them have at least one subscriber, a `false` is returned otherwise.
986+
987+
```mjs
988+
import diagnostics_channel from 'node:diagnostics_channel';
989+
990+
const channels = diagnostics_channel.tracingChannel('my-channel');
991+
992+
if (channels.hasSubscribers) {
993+
// Do something
994+
}
995+
```
996+
997+
```cjs
998+
const diagnostics_channel = require('node:diagnostics_channel');
999+
1000+
const channels = diagnostics_channel.tracingChannel('my-channel');
1001+
1002+
if (channels.hasSubscribers) {
1003+
// Do something
1004+
}
1005+
```
1006+
9701007
### TracingChannel Channels
9711008

9721009
A TracingChannel is a collection of several diagnostics\_channels representing
Collapse file
+51Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
'use strict';
2+
3+
const common = require('../common');
4+
const dc = require('diagnostics_channel');
5+
const assert = require('assert');
6+
7+
const handler = common.mustNotCall();
8+
9+
{
10+
const handlers = {
11+
start: common.mustNotCall()
12+
};
13+
14+
const channel = dc.tracingChannel('test');
15+
16+
assert.strictEqual(channel.hasSubscribers, false);
17+
18+
channel.subscribe(handlers);
19+
assert.strictEqual(channel.hasSubscribers, true);
20+
21+
channel.unsubscribe(handlers);
22+
assert.strictEqual(channel.hasSubscribers, false);
23+
24+
channel.start.subscribe(handler);
25+
assert.strictEqual(channel.hasSubscribers, true);
26+
27+
channel.start.unsubscribe(handler);
28+
assert.strictEqual(channel.hasSubscribers, false);
29+
}
30+
31+
{
32+
const handlers = {
33+
asyncEnd: common.mustNotCall()
34+
};
35+
36+
const channel = dc.tracingChannel('test');
37+
38+
assert.strictEqual(channel.hasSubscribers, false);
39+
40+
channel.subscribe(handlers);
41+
assert.strictEqual(channel.hasSubscribers, true);
42+
43+
channel.unsubscribe(handlers);
44+
assert.strictEqual(channel.hasSubscribers, false);
45+
46+
channel.asyncEnd.subscribe(handler);
47+
assert.strictEqual(channel.hasSubscribers, true);
48+
49+
channel.asyncEnd.unsubscribe(handler);
50+
assert.strictEqual(channel.hasSubscribers, false);
51+
}

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.