(fn: () => Promise<T>, attempts = 3)
| 6 | }); |
| 7 | |
| 8 | export const retryFn = async <T>(fn: () => Promise<T>, attempts = 3): Promise<T> => { |
| 9 | while (true) { |
| 10 | try { |
| 11 | return await fn(); |
| 12 | } catch (error) { |
| 13 | if (attempts <= 0) { |
| 14 | return Promise.reject(error); |
| 15 | } |
| 16 | await delay(500); |
| 17 | attempts--; |
| 18 | } |
| 19 | } |
| 20 | }; |
| 21 | |
| 22 | export const withTimeout = async <T>( |
| 23 | promise: Promise<T>, |
no test coverage detected