Skip to content

Commit

Permalink
lib: fix diagnostics_channel hasSubscribers error
Browse files Browse the repository at this point in the history
Fixes: #36598

PR-URL: #36599
Reviewed-By: Antoine du Hamel <[email protected]>
Reviewed-By: Luigi Pinca <[email protected]>
Reviewed-By: Rich Trott <[email protected]>
  • Loading branch information
Lxxyx authored and targos committed May 1, 2021
1 parent 317a1d7 commit 08b69fb
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
3 changes: 1 addition & 2 deletions lib/diagnostics_channel.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ const {
ObjectGetPrototypeOf,
ObjectSetPrototypeOf,
SymbolHasInstance,
WeakRefPrototypeGet
} = primordials;

const {
Expand Down Expand Up @@ -107,7 +106,7 @@ function channel(name) {
function hasSubscribers(name) {
let channel;
const ref = channels[name];
if (ref) channel = WeakRefPrototypeGet(ref);
if (ref) channel = ref.get();
if (!channel) {
return false;
}
Expand Down
10 changes: 10 additions & 0 deletions test/parallel/test-diagnostics-channel-has-subscribers.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
'use strict';
require('../common');
const assert = require('assert');
const { channel, hasSubscribers } = require('diagnostics_channel');

const dc = channel('test');
assert.ok(!hasSubscribers('test'));

dc.subscribe(() => {});
assert.ok(hasSubscribers('test'));

0 comments on commit 08b69fb

Please sign in to comment.