mirror of
https://github.com/fluencelabs/js-libp2p
synced 2025-05-29 10:11:19 +00:00
fix: do not use assert in async funcs (#88)
This commit is contained in:
parent
e4e9761c99
commit
2e326e1619
24
src/index.js
24
src/index.js
@ -82,7 +82,9 @@ class Node extends EventEmitter {
|
|||||||
|
|
||||||
this.peerRouting = {
|
this.peerRouting = {
|
||||||
findPeer: (id, callback) => {
|
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)
|
this._dht.findPeer(id, callback)
|
||||||
}
|
}
|
||||||
@ -90,12 +92,16 @@ class Node extends EventEmitter {
|
|||||||
|
|
||||||
this.contentRouting = {
|
this.contentRouting = {
|
||||||
findProviders: (key, timeout, callback) => {
|
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)
|
this._dht.findProviders(key, timeout, callback)
|
||||||
},
|
},
|
||||||
provide: (key, 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)
|
this._dht.provide(key, callback)
|
||||||
}
|
}
|
||||||
@ -103,17 +109,23 @@ class Node extends EventEmitter {
|
|||||||
|
|
||||||
this.dht = {
|
this.dht = {
|
||||||
put: (key, value, callback) => {
|
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)
|
this._dht.put(key, value, callback)
|
||||||
},
|
},
|
||||||
get: (key, 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)
|
this._dht.get(key, callback)
|
||||||
},
|
},
|
||||||
getMany (key, nVals, 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)
|
this._dht.getMany(key, nVals, callback)
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user