Skip to content

Commit

Permalink
perf(LavaShark): Optimize get node ping function
Browse files Browse the repository at this point in the history
  • Loading branch information
hmes98318 committed Sep 15, 2023
1 parent 8f9b95d commit fe27bab
Showing 1 changed file with 4 additions and 21 deletions.
25 changes: 4 additions & 21 deletions src/lib/LavaShark.ts
Original file line number Diff line number Diff line change
Expand Up @@ -389,16 +389,16 @@ export class LavaShark extends EventEmitter {
const startTime = Date.now();

await Promise.race([
node.getStats(),
node.getVersion(),
new Promise<void>((_, reject) => {
setTimeout(() => {
reject(new Error('Update stats timed out'));
reject(new Error('Send ping data timed out.'));
}, timeout);
})
]);

const endTime = Date.now();
const ping = endTime - startTime;
const ping = endTime - startTime;
return ping;
} catch (_) {
return -1;
Expand All @@ -418,24 +418,7 @@ export class LavaShark extends EventEmitter {
}

const pingPromises = nodes.map(async (node) => {
try {
const startTime = Date.now();

await Promise.race([
node.getStats(),
new Promise<void>((_, reject) => {
setTimeout(() => {
reject(new Error('Update stats timed out'));
}, timeout);
})
]);

const endTime = Date.now();
const ping = endTime - startTime;
return ping;
} catch (_) {
return -1;
}
return this.nodePing(node);
});

const pingList = await Promise.all(pingPromises);
Expand Down

0 comments on commit fe27bab

Please sign in to comment.