Movatterモバイル変換


[0]ホーム

URL:


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

Sign up
Appearance settings

Commitf336e61

Browse files
tlhuntermarco-ippolito
authored andcommitted
doc, test: tracing channel hasSubscribers getter
follow up work for#51915PR-URL:#52908Reviewed-By: Stephen Belanger <admin@stephenbelanger.com>Reviewed-By: James M Snell <jasnell@gmail.com>
1 parent5eea419 commitf336e61

File tree

2 files changed

+88
-0
lines changed

2 files changed

+88
-0
lines changed

‎doc/api/diagnostics_channel.md

Lines changed: 37 additions & 0 deletions
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+
importdiagnostics_channelfrom'node:diagnostics_channel';
989+
990+
constchannels=diagnostics_channel.tracingChannel('my-channel');
991+
992+
if (channels.hasSubscribers) {
993+
// Do something
994+
}
995+
```
996+
997+
```cjs
998+
constdiagnostics_channel=require('node:diagnostics_channel');
999+
1000+
constchannels=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
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
'use strict';
2+
3+
constcommon=require('../common');
4+
constdc=require('diagnostics_channel');
5+
constassert=require('assert');
6+
7+
consthandler=common.mustNotCall();
8+
9+
{
10+
consthandlers={
11+
start:common.mustNotCall()
12+
};
13+
14+
constchannel=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+
consthandlers={
33+
asyncEnd:common.mustNotCall()
34+
};
35+
36+
constchannel=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)

[8]ページ先頭

©2009-2025 Movatter.jp