Skip to content

Commit b064c9b

Browse files
committed
add support for active channels
1 parent 962e8de commit b064c9b

File tree

1 file changed

+10
-8
lines changed
  • packages/diagnostics_channel/src

1 file changed

+10
-8
lines changed

packages/diagnostics_channel/src/index.js

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
'use strict'
22

33
const {
4-
Channel,
54
channel
65
} = require('diagnostics_channel') // eslint-disable-line n/no-restricted-require
76

87
const [major, minor] = process.versions.node.split('.')
8+
const channels = new WeakSet()
99

1010
// Our own DC with a limited subset of functionality stable across Node versions.
1111
// TODO: Move the rest of the polyfill here.
@@ -16,21 +16,23 @@ const dc = { channel }
1616
// See https://github.com/nodejs/node/pull/47520
1717
if (major === '19' && minor === '9') {
1818
dc.channel = function () {
19-
const maybeInactive = channel.apply(this, arguments)
19+
const ch = channel.apply(this, arguments)
2020

21-
if (maybeInactive.subscribe === Channel.prototype.subscribe) {
22-
const subscribe = maybeInactive.subscribe
21+
if (!channels.has(ch)) {
22+
const subscribe = ch.subscribe
2323

24-
maybeInactive.subscribe = function () {
25-
delete maybeInactive.subscribe
24+
ch.subscribe = function () {
25+
delete ch.subscribe
2626

2727
subscribe.apply(this, arguments)
2828

29-
this.subscribe(() => {}) // Keep it active forever.
29+
subscribe(() => {}) // Keep it active forever.
3030
}
31+
32+
channels.add(ch)
3133
}
3234

33-
return maybeInactive
35+
return ch
3436
}
3537
}
3638

0 commit comments

Comments
 (0)