fix: do not use assert in async funcs (#88)

This commit is contained in:
David Dias 2017-04-16 16:54:31 +01:00 committed by GitHub
parent e4e9761c99
commit 2e326e1619

View File

@ -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)
}