Skip to content

Commit 9c84119

Browse files
HermanBilousHerman Bilous
authored and
Herman Bilous
committed
Use Math.pow for retry delay calculation
1 parent 37728ee commit 9c84119

File tree

1 file changed

+2
-5
lines changed

1 file changed

+2
-5
lines changed

src/client.ts

+2-5
Original file line numberDiff line numberDiff line change
@@ -464,14 +464,11 @@ export function createClient<
464464
connectionAckWaitTimeout = 0,
465465
retryAttempts = 5,
466466
retryWait = async function randomisedExponentialBackoff(retries) {
467-
let retryDelay = 1000; // start with 1s delay
468-
for (let i = 0; i < retries; i++) {
469-
retryDelay *= 2;
470-
}
467+
const retryDelaySeconds = Math.pow(2, retries);
471468
await new Promise((resolve) =>
472469
setTimeout(
473470
resolve,
474-
retryDelay +
471+
retryDelaySeconds * 1000 +
475472
// add random timeout from 300ms to 3s
476473
Math.floor(Math.random() * (3000 - 300) + 300),
477474
),

0 commit comments

Comments
 (0)