Skip to content

Commit

Permalink
fix: sync leave() function (#378)
Browse files Browse the repository at this point in the history
* fix: sync leave() function

* fix: delete mesh at the end of leave() function
  • Loading branch information
twoeths authored Dec 1, 2022
1 parent 7a20b0c commit ac7fd52
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1758,9 +1758,7 @@ export class GossipSub extends EventEmitter<GossipsubEvents> implements PubSub<G
}
}

this.leave(topic).catch((err) => {
this.log(err)
})
this.leave(topic)
}

/**
Expand Down Expand Up @@ -1834,7 +1832,7 @@ export class GossipSub extends EventEmitter<GossipsubEvents> implements PubSub<G
/**
* Leave topic
*/
private async leave(topic: TopicStr): Promise<void> {
private leave(topic: TopicStr): void {
if (this.status.code !== GossipStatusCode.started) {
throw new Error('Gossipsub has not started')
}
Expand All @@ -1845,12 +1843,14 @@ export class GossipSub extends EventEmitter<GossipsubEvents> implements PubSub<G
// Send PRUNE to mesh peers
const meshPeers = this.mesh.get(topic)
if (meshPeers) {
await Promise.all(
Promise.all(
Array.from(meshPeers).map(async (id) => {
this.log('LEAVE: Remove mesh link to %s in %s', id, topic)
return await this.sendPrune(id, topic)
})
)
).catch((err) => {
this.log('Error sending prunes to mesh peers', err)
})
this.mesh.delete(topic)
}
}
Expand Down

0 comments on commit ac7fd52

Please sign in to comment.