Function
execWithRetry
(
fn: () => Promise<any>,
options: ExecWithRetryOptions = ExecWithRetrySchema.parse({}),
)
Source from the content-addressed store, hash-verified
| 45 | export type ExecWithRetryOptions = Z.infer<typeof ExecWithRetrySchema>; |
| 46 | |
| 47 | export async function execWithRetry( |
| 48 | fn: () => Promise<any>, |
| 49 | options: ExecWithRetryOptions = ExecWithRetrySchema.parse({}), |
| 50 | ) { |
| 51 | let lastError: any; |
| 52 | |
| 53 | for (let i = 0; i < options.attempts; i++) { |
| 54 | try { |
| 55 | return await fn(); |
| 56 | } catch (error: any) { |
| 57 | lastError = error; |
| 58 | await delay(options.delay); |
| 59 | } |
| 60 | } |
| 61 | |
| 62 | throw lastError; |
| 63 | } |
| 64 | |
| 65 | // Helpers |
| 66 | |
Callers
nothing calls this directly
Tested by
no test coverage detected