From 6d07e4dbde53ac320d0c5627cf807e0bcdb6e424 Mon Sep 17 00:00:00 2001 From: simon-id Date: Tue, 12 Oct 2021 22:42:50 +0200 Subject: [PATCH] lib: add success return bool in unsubscribe --- lib/diagnostics_channel.js | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/lib/diagnostics_channel.js b/lib/diagnostics_channel.js index b96e06c7c03431..c85a9532b4d372 100644 --- a/lib/diagnostics_channel.js +++ b/lib/diagnostics_channel.js @@ -32,15 +32,17 @@ class ActiveChannel { unsubscribe(subscription) { const index = ArrayPrototypeIndexOf(this._subscribers, subscription); - if (index >= 0) { - ArrayPrototypeSplice(this._subscribers, index, 1); + if (index === -1) return false; - // When there are no more active subscribers, restore to fast prototype. - if (!this._subscribers.length) { - // eslint-disable-next-line no-use-before-define - ObjectSetPrototypeOf(this, Channel.prototype); - } + ArrayPrototypeSplice(this._subscribers, index, 1); + + // When there are no more active subscribers, restore to fast prototype. + if (!this._subscribers.length) { + // eslint-disable-next-line no-use-before-define + ObjectSetPrototypeOf(this, Channel.prototype); } + + return true; } get hasSubscribers() { @@ -79,7 +81,9 @@ class Channel { this.subscribe(subscription); } - unsubscribe() {} + unsubscribe() { + return false; + } get hasSubscribers() { return false;