File tree Expand file tree Collapse file tree
packages/diagnostics_channel/src Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11'use strict'
22
33const {
4- Channel,
54 channel
65} = require ( 'diagnostics_channel' ) // eslint-disable-line n/no-restricted-require
76
87const [ 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
1717if ( 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
You can’t perform that action at this time.
0 commit comments