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,
45 channel
56} = require ( 'diagnostics_channel' ) // eslint-disable-line n/no-restricted-require
67
@@ -20,9 +21,11 @@ if (major === '19' && minor === '9') {
2021
2122 if ( ! channels . has ( ch ) ) {
2223 const subscribe = ch . subscribe
24+ const unsubscribe = ch . unsubscribe
2325
2426 ch . subscribe = function ( ) {
2527 delete ch . subscribe
28+ delete ch . unsubscribe
2629
2730 const result = subscribe . apply ( this , arguments )
2831
@@ -31,6 +34,19 @@ if (major === '19' && minor === '9') {
3134 return result
3235 }
3336
37+ if ( ch . unsubscribe === Channel . prototype . unsubscribe ) {
38+ // Needed because another subscriber could have subscribed to something
39+ // that we unsubscribe to before the library is loaded.
40+ ch . unsubscribe = function ( ) {
41+ delete ch . subscribe
42+ delete ch . unsubscribe
43+
44+ this . subscribe ( ( ) => { } ) // Keep it active forever.
45+
46+ return unsubscribe . apply ( this , arguments )
47+ }
48+ }
49+
3450 channels . add ( ch )
3551 }
3652
You can’t perform that action at this time.
0 commit comments