MCPcopy
hub / github.com/blitz-js/blitz / retry

Function retry

integration-tests/utils/next-test-utils.ts:664–683  ·  view source on GitHub ↗
(fn, duration = 3000, interval = 500, description)

Source from the content-addressed store, hash-verified

662}
663
664export async function retry(fn, duration = 3000, interval = 500, description) {
665 if (duration % interval !== 0) {
666 throw new Error(
667 `invalid duration ${duration} and interval ${interval} mix, duration must be evenly divisible by interval`,
668 )
669 }
670
671 for (let i = duration; i >= 0; i -= interval) {
672 try {
673 return await fn()
674 } catch (err) {
675 if (i === 0) {
676 console.error(`Failed to retry${description ? ` ${description}` : ""} within ${duration}ms`)
677 throw err
678 }
679 console.warn(`Retrying${description ? ` ${description}` : ""} in ${interval}ms`)
680 await waitFor(interval)
681 }
682 }
683}
684
685export async function hasRedbox(browser, expected = true) {
686 for (let i = 0; i < 30; i++) {

Callers 3

getRedboxHeaderFunction · 0.85
getRedboxSourceFunction · 0.85
getRedboxDescriptionFunction · 0.85

Calls 3

waitForFunction · 0.85
errorMethod · 0.80
warnMethod · 0.80

Tested by

no test coverage detected