mirror of
https://github.com/fluencelabs/js-libp2p
synced 2025-07-06 12:21:36 +00:00
fix: add maxtimeout to dht get (#248)
* fix: add maxtimeout to dht get * chore: add tests
This commit is contained in:
18
src/dht.js
18
src/dht.js
@ -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)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user