(fn, label, attempts, delayMs)
| 634 | } |
| 635 | |
| 636 | function retrySync(fn, label, attempts, delayMs) { |
| 637 | let lastError; |
| 638 | for (let attempt = 1; attempt <= attempts; attempt += 1) { |
| 639 | try { |
| 640 | return fn(); |
| 641 | } catch (error) { |
| 642 | lastError = error; |
| 643 | if (attempt < attempts) { |
| 644 | sleepSync(delayMs); |
| 645 | } |
| 646 | } |
| 647 | } |
| 648 | throw new Error( |
| 649 | `${label} failed after ${attempts} attempts: ${lastError?.message ?? lastError}`, |
| 650 | ); |
| 651 | } |
| 652 | |
| 653 | async function measuredStep(label, fn, options = {}) { |
| 654 | const parentTiming = activeTiming; |
no test coverage detected