Created
September 9, 2021 10:34
-
-
Save tsh-code/dd8631c6293e633a94a90502c78a23b6 to your computer and use it in GitHub Desktop.
This file contains 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
import { backOff } from "exponential-backoff"; | |
function getUsers() { | |
return fetch("/api/users"); | |
} | |
async function main() { | |
try { | |
// If request fails (ex. we are blocked by rate limit) it will be | |
//retried automatically after a random period of time! | |
const response = await backOff(() => getUsers()); | |
// process response | |
} catch (e) { | |
// handle error | |
} | |
} | |
main(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment