Skip to content

Commit

Permalink
lib: add success return bool in unsubscribe
Browse files Browse the repository at this point in the history
  • Loading branch information
simon-id committed Oct 12, 2021
1 parent 64fdae3 commit 6d07e4d
Showing 1 changed file with 12 additions and 8 deletions.
20 changes: 12 additions & 8 deletions lib/diagnostics_channel.js
Expand Up @@ -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() {
Expand Down Expand Up @@ -79,7 +81,9 @@ class Channel {
this.subscribe(subscription);
}

unsubscribe() {}
unsubscribe() {
return false;
}

get hasSubscribers() {
return false;
Expand Down

0 comments on commit 6d07e4d

Please sign in to comment.