Function
retryAsync
(fn, label, attempts, delayMs)
Source from the content-addressed store, hash-verified
| 617 | } |
| 618 | |
| 619 | async function retryAsync(fn, label, attempts, delayMs) { |
| 620 | let lastError; |
| 621 | for (let attempt = 1; attempt <= attempts; attempt += 1) { |
| 622 | try { |
| 623 | return await fn(); |
| 624 | } catch (error) { |
| 625 | lastError = error; |
| 626 | if (attempt < attempts) { |
| 627 | await sleep(delayMs); |
| 628 | } |
| 629 | } |
| 630 | } |
| 631 | throw new Error( |
| 632 | `${label} failed after ${attempts} attempts: ${lastError?.message ?? lastError}`, |
| 633 | ); |
| 634 | } |
| 635 | |
| 636 | function retrySync(fn, label, attempts, delayMs) { |
| 637 | let lastError; |
Tested by
no test coverage detected