Skip to content

Commit a9cb6cc

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

File tree

2 files changed

+7
-5
lines changed

2 files changed

+7
-5
lines changed

.changeset/flat-mice-hope.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'graphql-ws': patch
3+
---
4+
5+
Use Math.pow for retry delay calculation

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)