*Try to update the available list every loop and only compare max _activeRelays against the min of _maxConnections and available
This commit is contained in:
parent
cb16b87b73
commit
5f37b74baf
10
src/index.ts
10
src/index.ts
|
@ -123,16 +123,22 @@ export default class DHT {
|
|||
}
|
||||
|
||||
private async fillConnections(): Promise<any> {
|
||||
let available = [...this._relays.keys()].filter(
|
||||
let available: string[] = [];
|
||||
|
||||
const updateAvailable = () => {
|
||||
available = [...this._relays.keys()].filter(
|
||||
(x) => ![...this._activeRelays.keys()].includes(x)
|
||||
);
|
||||
};
|
||||
updateAvailable();
|
||||
|
||||
let relayPromises = [];
|
||||
if (0 === available.length) {
|
||||
return;
|
||||
}
|
||||
while (
|
||||
this._activeRelays.size <=
|
||||
Math.min(this._maxConnections, available.length + this._activeRelays.size)
|
||||
Math.min(this._maxConnections, available.length)
|
||||
) {
|
||||
const relayIndex = await randomNumber(0, available.length - 1);
|
||||
|
||||
|
|
Loading…
Reference in New Issue