mirror of
https://github.com/fluencelabs/js-libp2p
synced 2025-03-16 15:40:49 +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 = {
|
||||
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)
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user