Skip to content
Source
Sign inSign up
TanStack/db
Open History to see the last commit

BackoffCalculator.ts

13 lines364 Bytes

1export class BackoffCalculator {
2 private jitter: boolean
3​
4 constructor(jitter = true) {
5 this.jitter = jitter
6 }
7​
8 calculate(retryCount: number): number {
9 const baseDelay = Math.min(1000 * Math.pow(2, retryCount), 60000)
10 const jitterMultiplier = this.jitter ? Math.random() * 0.3 : 0
11 return Math.floor(baseDelay * (1 + jitterMultiplier))
12 }