(options: RetryOptions, attempt: number)
| 27 | * @returns |
| 28 | */ |
| 29 | export function calculateNextRetryDelay(options: RetryOptions, attempt: number) { |
| 30 | const opts = { ...defaultRetryOptions, ...options }; |
| 31 | |
| 32 | if (attempt >= opts.maxAttempts) { |
| 33 | return; |
| 34 | } |
| 35 | |
| 36 | const { factor, minTimeoutInMs, maxTimeoutInMs, randomize } = opts; |
| 37 | |
| 38 | const random = randomize ? Math.random() + 1 : 1; |
| 39 | |
| 40 | const timeout = Math.min(maxTimeoutInMs, random * minTimeoutInMs * Math.pow(factor, attempt - 1)); |
| 41 | |
| 42 | // Round to the nearest integer |
| 43 | return Math.round(timeout); |
| 44 | } |
| 45 | |
| 46 | export function calculateResetAt( |
| 47 | resets: string | undefined | null, |
no test coverage detected
searching dependent graphs…