Skip to content

Instantly share code, notes, and snippets.

@CodeMan99
Created November 2, 2022 15:21
Show Gist options
  • Save CodeMan99/b406a708bf23146b9313fab41f684a73 to your computer and use it in GitHub Desktop.
Save CodeMan99/b406a708bf23146b9313fab41f684a73 to your computer and use it in GitHub Desktop.
Exponential Back-Off
// snippet based on https://github.com/tim-kos/node-retry#retrytimeoutsoptions
const timeouts = Array.from({length: 10}, (_, i) => {
const random = 1;
const minTimeout = 10;
const factor = 2;
const attempt = i;
const maxTimeout = 6000;
return Math.min(random * minTimeout * Math.pow(factor, attempt), maxTimeout);
});
console.dir(timeouts);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment