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

Commit

Permalink
fix: really nasty race condition that would only happen on travis whi…
Browse files Browse the repository at this point in the history
…le running js-ipfs tests
  • Loading branch information
daviddias committed May 12, 2017
1 parent 39fd6e4 commit 09220b9
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ const Peer = require('./peer')
const utils = require('./utils')
const pb = require('./message')
const config = require('./config')
const Buffer = require('safe-buffer').Buffer

const log = config.log
const multicodec = config.multicodec
Expand Down Expand Up @@ -304,9 +305,15 @@ class FloodSub extends EventEmitter {
this.subscriptions.add(topic)
})

this.peers.forEach((peer) => {
peer.sendSubscriptions(topics)
})
this.peers.forEach((peer) => checkIfReady(peer))
// make sure that FloodSub is already mounted
function checkIfReady (peer) {
if (peer.isWritable) {
peer.sendSubscriptions(topics)
} else {
setTimeout(checkIfReady.bind(peer), 100)
}
}
}

/**
Expand Down

0 comments on commit 09220b9

Please sign in to comment.