(retryOptions: RetryOptions, attempts: number)
| 9 | } satisfies RetryOptions; |
| 10 | |
| 11 | export function calculateRetryAt(retryOptions: RetryOptions, attempts: number): Date | undefined { |
| 12 | const options = { |
| 13 | ...DEFAULT_RETRY_OPTIONS, |
| 14 | ...retryOptions, |
| 15 | }; |
| 16 | |
| 17 | const retryCount = attempts + 1; |
| 18 | |
| 19 | if (retryCount >= options.limit) { |
| 20 | return; |
| 21 | } |
| 22 | |
| 23 | const random = options.randomize ? Math.random() + 1 : 1; |
| 24 | |
| 25 | let timeoutInMs = Math.round( |
| 26 | random * |
| 27 | Math.max(options.minTimeoutInMs, 1) * |
| 28 | Math.pow(options.factor, Math.max(attempts - 1, 0)) |
| 29 | ); |
| 30 | |
| 31 | timeoutInMs = Math.min(timeoutInMs, options.maxTimeoutInMs); |
| 32 | |
| 33 | return new Date(Date.now() + timeoutInMs); |
| 34 | } |
| 35 | |
| 36 | export function calculateResetAt( |
| 37 | resets: string | undefined | null, |
no test coverage detected
searching dependent graphs…