Add temporary timeout for blob peer list lookups
Returns an empty array for the peer list if the API call takes more than 6 seconds. If the lookup takes that long, there are almost never never any peers.
This commit is contained in:
parent
3c339492a0
commit
f3a501cf14
1 changed files with 13 additions and 1 deletions
14
js/lbry.js
14
js/lbry.js
|
@ -5,6 +5,7 @@ var lbry = {
|
|||
rootPath: '.',
|
||||
daemonConnectionString: 'http://localhost:5279/lbryapi',
|
||||
webUiUri: 'http://localhost:5279',
|
||||
peerListTimeout: 6000,
|
||||
colors: {
|
||||
primary: '#155B4A'
|
||||
},
|
||||
|
@ -190,7 +191,18 @@ lbry.getTotalCost = function(name, size, callback) {
|
|||
}
|
||||
|
||||
lbry.getPeersForBlobHash = function(blobHash, callback) {
|
||||
lbry.call('peer_list', { blob_hash: blobHash }, callback);
|
||||
let timedOut = false;
|
||||
const timeout = setTimeout(() => {
|
||||
timedOut = true;
|
||||
callback([]);
|
||||
}, lbry.peerListTimeout);
|
||||
|
||||
lbry.call('peer_list', { blob_hash: blobHash }, function(peers) {
|
||||
if (!timedOut) {
|
||||
clearTimeout(timeout);
|
||||
callback(peers);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
lbry.getCostInfoForName = function(name, callback) {
|
||||
|
|
Loading…
Reference in a new issue