Skip to content

Commit

Permalink
Use Math.pow for retry delay calculation
Browse files Browse the repository at this point in the history
  • Loading branch information
HermanBilous authored and Herman Bilous committed Feb 12, 2025
1 parent 37728ee commit 9c84119
Showing 1 changed file with 2 additions and 5 deletions.
7 changes: 2 additions & 5 deletions src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -464,14 +464,11 @@ export function createClient<
connectionAckWaitTimeout = 0,
retryAttempts = 5,
retryWait = async function randomisedExponentialBackoff(retries) {
let retryDelay = 1000; // start with 1s delay
for (let i = 0; i < retries; i++) {
retryDelay *= 2;
}
const retryDelaySeconds = Math.pow(2, retries);
await new Promise((resolve) =>
setTimeout(
resolve,
retryDelay +
retryDelaySeconds * 1000 +
// add random timeout from 300ms to 3s
Math.floor(Math.random() * (3000 - 300) + 300),
),
Expand Down

0 comments on commit 9c84119

Please sign in to comment.