-
Notifications
You must be signed in to change notification settings - Fork 30.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
diagnostics_channel: handle last subscriber removal
When iterating over diagnostics channel subscribers, assume their count is zero if the list of subscribers becomes undefined, because there may be only one subscriber which may unsubscribe itself as part of its onMessage handler.
- Loading branch information
1 parent
14e7bd8
commit 7d6b3f2
Showing
2 changed files
with
15 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
14 changes: 14 additions & 0 deletions
14
test/parallel/test-diagnostics-channel-sync-unsubscribe.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
'use strict'; | ||
|
||
const common = require('../common'); | ||
const dc = require('node:diagnostics_channel'); | ||
|
||
const channel_name = 'test:channel'; | ||
const published_data = 'some message'; | ||
|
||
const onMessageHandler = common.mustCall(() => dc.unsubscribe(channel_name, onMessageHandler)); | ||
|
||
dc.subscribe(channel_name, onMessageHandler); | ||
|
||
// This must not throw. | ||
dc.channel(channel_name).publish(published_data); |