Skip to content

Instantly share code, notes, and snippets.

@tsh-code
Created September 9, 2021 10:34
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 tsh-code/dd8631c6293e633a94a90502c78a23b6 to your computer and use it in GitHub Desktop.
Save tsh-code/dd8631c6293e633a94a90502c78a23b6 to your computer and use it in GitHub Desktop.
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