MCPcopy Create free account
hub / github.com/github/docs / retryOnErrorTest

Function retryOnErrorTest

script/helpers/retry-on-error-test.js:25–43  ·  view source on GitHub ↗
(
  errorTest,
  callback,
  { attempts = 10, sleepTime = 1000, onError = () => {} } = {}
)

Source from the content-addressed store, hash-verified

23const sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms))
24
25export async function retryOnErrorTest(
26 errorTest,
27 callback,
28 { attempts = 10, sleepTime = 1000, onError = () => {} } = {}
29) {
30 while (--attempts) {
31 try {
32 return await callback()
33 } catch (error) {
34 if (errorTest(error)) {
35 // console.warn('Sleeping on', error.message, { attempts })
36 if (onError) onError(error, attempts)
37 await sleep(sleepTime)
38 } else {
39 throw error
40 }
41 }
42 }
43}

Callers 1

indexVersionFunction · 0.90

Calls 1

sleepFunction · 0.70

Tested by

no test coverage detected