Skip to content

Commit

Permalink
fix: add splice leader
Browse files Browse the repository at this point in the history
  • Loading branch information
IsaccoSordo committed Sep 21, 2024
1 parent 9657046 commit 9932af0
Showing 1 changed file with 2 additions and 3 deletions.
5 changes: 2 additions & 3 deletions packages/beacon-core/src/utils/multi-tab-channel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ export class MultiTabChannel {
}

setInterval(() => {
this.leaderElection()
this.leaderElection(Array.from(this.neighborhood).filter((id) => id !== this.leaderID))
this.postMessage({ type: 'HEARTBEAT' })
}, timeout * 2)
}
Expand All @@ -118,11 +118,10 @@ export class MultiTabChannel {
this.pendingACKs.delete(this.leaderID)
}

private leaderElection() {
private leaderElection(neighborhood = Array.from(this.neighborhood)) {
this.pendingACKs.set(
this.leaderID,
setTimeout(() => {
const neighborhood = Array.from(this.neighborhood)
this.leaderID = neighborhood[0]
if (neighborhood[0] !== this.id) {
return
Expand Down

0 comments on commit 9932af0

Please sign in to comment.