Skip to content

Commit

Permalink
fix: remove event listeners first on close
Browse files Browse the repository at this point in the history
  • Loading branch information
marcus-pousette committed Dec 5, 2023
1 parent 241d009 commit 6b107e4
Showing 1 changed file with 11 additions and 30 deletions.
41 changes: 11 additions & 30 deletions packages/programs/data/shared-log/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -393,6 +393,17 @@ export class SharedLog<T = Uint8Array> extends Program<
private async _close() {
this._closeController.abort();

this.node.services.pubsub.removeEventListener(
"subscribe",
this._onSubscriptionFn
);

this._onUnsubscriptionFn = this._onUnsubscription.bind(this);
this.node.services.pubsub.removeEventListener(
"unsubscribe",
this._onUnsubscriptionFn
);

for (const [k, v] of this._pendingDeletes) {
v.clear();
v.promise.resolve(); // TODO or reject?
Expand All @@ -410,17 +421,6 @@ export class SharedLog<T = Uint8Array> extends Program<
this._gidPeersHistory = new Map();
this._sortedPeersCache = undefined;
this._loadedOnce = false;

this.node.services.pubsub.removeEventListener(
"subscribe",
this._onSubscriptionFn
);

this._onUnsubscriptionFn = this._onUnsubscription.bind(this);
this.node.services.pubsub.removeEventListener(
"unsubscribe",
this._onUnsubscriptionFn
);
}
async close(from?: Program): Promise<boolean> {
const superClosed = await super.close(from);
Expand Down Expand Up @@ -799,25 +799,6 @@ export class SharedLog<T = Uint8Array> extends Program<
return this.findLeadersFromUniformNumber(cursor, numberOfLeaders, options);
}

/* getParticipationSum(age: number) {
let sum = 0;
const t = +new Date;
let currentNode = this.getReplicatorsSorted()?.head;
while (currentNode) {
const value = currentNode.value;
if (t - value.timestamp > age || currentNode.value.publicKey.equals(this.node.identity.publicKey)) {
sum += value.length;
}
if (sum >= 1) {
return 1;
}
currentNode = currentNode.next
}
return sum;
} */

private findLeadersFromUniformNumber(
cursor: number,
numberOfLeaders: number,
Expand Down

0 comments on commit 6b107e4

Please sign in to comment.