fix: dont call callback before it's properly set

This commit is contained in:
Jacob Heun
2018-11-05 13:56:45 +01:00
parent c18d2a4147
commit 17b5f73b3d
4 changed files with 58 additions and 8 deletions

View File

@ -22,15 +22,15 @@ module.exports = (node) => {
* @returns {void}
*/
findPeer: (id, options, callback) => {
if (!routers.length) {
callback(errCode(new Error('No peer routers available'), 'NO_ROUTERS_AVAILABLE'))
}
if (typeof options === 'function') {
callback = options
options = {}
}
if (!routers.length) {
callback(errCode(new Error('No peer routers available'), 'NO_ROUTERS_AVAILABLE'))
}
const tasks = routers.map((router) => {
return (cb) => router.findPeer(id, options, (err, result) => {
if (err) {