Skip to content

Instantly share code, notes, and snippets.

@slonoed
Forked from mordaha/testEpic.js
Last active September 21, 2017 13:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save slonoed/001b4c7033b518caa0695447e05094be to your computer and use it in GitHub Desktop.
Save slonoed/001b4c7033b518caa0695447e05094be to your computer and use it in GitHub Desktop.
async function retry(foo, count = 1, delay) {
let error;
while (count--) {
try {
return foo()
} catch (e) {
error = e
await timeout(delay)
}
}
throw error
}
async function testEpic() {
try {
const foo = () => fetch('/1234')
const data = retry(foo, 3, 3000)
dispatch(data)
} catch (e) {
dispatch(e)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment