Last active
August 14, 2018 08:57
-
-
Save Calvin-Huang/a0e0883c338cae75cd300d16a2ceb930 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Retry 5 times with waiting for 2 seconds | |
function* updateApi(data) { | |
for(let i = 0; i < 5; i++) { | |
try { | |
const apiResponse = yield call(apiRequest, { data }); | |
return apiResponse; | |
} catch(err) { | |
if(i < 4) { | |
yield call(delay, 2000); | |
} | |
} | |
} | |
// attempts failed after 5 attempts | |
throw new Error('API request failed'); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment