*Call updateAvailable in loop
*Check available length and abort and return if empty
This commit is contained in:
parent
00b0fe29f3
commit
cb139131e1
|
@ -133,13 +133,14 @@ export default class DHT {
|
|||
updateAvailable();
|
||||
|
||||
let relayPromises = [];
|
||||
if (0 === available.length) {
|
||||
return;
|
||||
}
|
||||
while (
|
||||
this._activeRelays.size <=
|
||||
Math.min(this._maxConnections, available.length)
|
||||
) {
|
||||
if (0 === available.length) {
|
||||
break;
|
||||
}
|
||||
|
||||
const relayIndex = await randomNumber(0, available.length - 1);
|
||||
|
||||
const connection = this._relays.get(available[relayIndex]) as string;
|
||||
|
@ -153,6 +154,7 @@ export default class DHT {
|
|||
this._options
|
||||
);
|
||||
this._activeRelays.set(available[relayIndex], node);
|
||||
updateAvailable();
|
||||
|
||||
relayPromises.push(node.ready());
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue