fix: add maxtimeout to dht get (#248)

* fix: add maxtimeout to dht get

* chore: add tests
This commit is contained in:
Vasco Santos
2018-09-19 18:31:36 +01:00
committed by Jacob Heun
parent e052021397
commit 69f7264123
3 changed files with 181 additions and 4 deletions

View File

@ -9,19 +9,29 @@ module.exports = (node) => {
node._dht.put(key, value, callback)
},
get: (key, callback) => {
get: (key, maxTimeout, callback) => {
if (typeof maxTimeout === 'function') {
callback = maxTimeout
maxTimeout = null
}
if (!node._dht) {
return callback(new Error('DHT is not available'))
}
node._dht.get(key, callback)
node._dht.get(key, maxTimeout, callback)
},
getMany (key, nVals, callback) {
getMany: (key, nVals, maxTimeout, callback) => {
if (typeof maxTimeout === 'function') {
callback = maxTimeout
maxTimeout = null
}
if (!node._dht) {
return callback(new Error('DHT is not available'))
}
node._dht.getMany(key, nVals, callback)
node._dht.getMany(key, nVals, maxTimeout, callback)
}
}
}