Skip to content
This repository has been archived by the owner on Jun 27, 2023. It is now read-only.

Commit

Permalink
fix: avoid race condition on unsubscribe
Browse files Browse the repository at this point in the history
  • Loading branch information
daviddias committed May 16, 2017
1 parent e8a3ef6 commit 8cf5498
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -332,9 +332,15 @@ class FloodSub extends EventEmitter {
this.subscriptions.delete(topic)
})

this.peers.forEach((peer) => {
peer.sendUnsubscriptions(topics)
})
this.peers.forEach((peer) => checkIfReady(peer))
// make sure that FloodSub is already mounted
function checkIfReady (peer) {
if (peer && peer.isWritable) {
peer.sendUnsubscriptions(topics)
} else {
setImmediate(checkIfReady.bind(peer))
}
}
}
}

Expand Down

0 comments on commit 8cf5498

Please sign in to comment.