From 2e326e1619c0337d97612c708e94950dfbd9a6ec Mon Sep 17 00:00:00 2001 From: David Dias Date: Sun, 16 Apr 2017 16:54:31 +0100 Subject: [PATCH] fix: do not use assert in async funcs (#88) --- src/index.js | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/src/index.js b/src/index.js index fddef7883d..35acefb9c4 100644 --- a/src/index.js +++ b/src/index.js @@ -82,7 +82,9 @@ class Node extends EventEmitter { this.peerRouting = { findPeer: (id, callback) => { - assert(this._dht, 'DHT is not available') + if (!this._dht) { + return callback(new Error('DHT is not available')) + } this._dht.findPeer(id, callback) } @@ -90,12 +92,16 @@ class Node extends EventEmitter { this.contentRouting = { findProviders: (key, timeout, callback) => { - assert(this._dht, 'DHT is not available') + if (!this._dht) { + return callback(new Error('DHT is not available')) + } this._dht.findProviders(key, timeout, callback) }, provide: (key, callback) => { - assert(this._dht, 'DHT is not available') + if (!this._dht) { + return callback(new Error('DHT is not available')) + } this._dht.provide(key, callback) } @@ -103,17 +109,23 @@ class Node extends EventEmitter { this.dht = { put: (key, value, callback) => { - assert(this._dht, 'DHT is not available') + if (!this._dht) { + return callback(new Error('DHT is not available')) + } this._dht.put(key, value, callback) }, get: (key, callback) => { - assert(this._dht, 'DHT is not available') + if (!this._dht) { + return callback(new Error('DHT is not available')) + } this._dht.get(key, callback) }, getMany (key, nVals, callback) { - assert(this._dht, 'DHT is not available') + if (!this._dht) { + return callback(new Error('DHT is not available')) + } this._dht.getMany(key, nVals, callback) }