Skip to content

Commit

Permalink
fix: do not use assert in async funcs (#88)
Browse files Browse the repository at this point in the history
  • Loading branch information
daviddias authored Apr 16, 2017
1 parent e4e9761 commit 2e326e1
Showing 1 changed file with 18 additions and 6 deletions.
24 changes: 18 additions & 6 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,38 +82,50 @@ 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)
}
}

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

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)
}
Expand Down

0 comments on commit 2e326e1

Please sign in to comment.