Gathering detailed insights and metrics for exponential-backoff
Gathering detailed insights and metrics for exponential-backoff
Gathering detailed insights and metrics for exponential-backoff
Gathering detailed insights and metrics for exponential-backoff
@ide/backoff
Computes truncated exponential backoff intervals with jitter
retry-cli
Retry with exponential backoff for the command line.
exponential-backoff-generator
Exponential backoff generator. Robust retry function.
backoff-rxjs
A collection of helpful RxJS operators to deal with backoff strategies (like exponential backoff)
A utility that allows retrying a function with an exponential delay between attempts.
npm install exponential-backoff
Module System
Min. Node Version
Typescript Support
Node Version
NPM Version
359 Stars
93 Commits
26 Forks
10 Watching
2 Branches
4 Contributors
Updated on 14 Nov 2024
TypeScript (100%)
Cumulative downloads
Total Downloads
Last day
-0.6%
1,906,238
Compared to previous day
Last week
4.4%
10,129,491
Compared to previous week
Last month
11%
41,848,649
Compared to previous month
Last year
297.9%
384,412,357
Compared to previous year
8
A utility that allows retrying a function with an exponential delay between attempts.
npm i exponential-backoff
The backOff<T>
function takes a promise-returning function to retry, and an optional BackOffOptions
object. It returns a Promise<T>
.
1function backOff<T>( 2 request: () => Promise<T>, 3 options?: BackOffOptions 4): Promise<T>;
Here is an example retrying a function that calls a hypothetical weather endpoint:
1import { backOff } from "exponential-backoff"; 2 3function getWeather() { 4 return fetch("weather-endpoint"); 5} 6 7async function main() { 8 try { 9 const response = await backOff(() => getWeather()); 10 // process response 11 } catch (e) { 12 // handle error 13 } 14} 15 16main();
Migrating across major versions? Here are our breaking changes.
BackOffOptions
delayFirstAttempt?: boolean
Decides whether the startingDelay
should be applied before the first call. If false
, the first call will occur without a delay.
Default value is false
.
jitter?: JitterType | string
Decides whether a jitter should be applied to the delay. Possible values are full
and none
.
Default value is none
.
maxDelay?: number
The maximum delay, in milliseconds, between two consecutive attempts.
Default value is Infinity
.
numOfAttempts?: number
The maximum number of times to attempt the function.
Default value is 10
.
Minimum value is 1
.
retry?: (e: any, attemptNumber: number) => boolean | Promise<boolean>
The retry
function can be used to run logic after every failed attempt (e.g. logging a message, assessing the last error, etc.). It is called with the last error and the upcoming attempt number. Returning true
will retry the function as long as the numOfAttempts
has not been exceeded. Returning false
will end the execution.
Default value is a function that always returns true
.
startingDelay?: number
The delay, in milliseconds, before executing the function for the first time.
Default value is 100
ms.
timeMultiple?: number
The startingDelay
is multiplied by the timeMultiple
to increase the delay between reattempts.
Default value is 2
.
No vulnerabilities found.
Reason
all changesets reviewed
Reason
no dangerous workflow patterns detected
Reason
no binaries found in the repo
Reason
license file detected
Details
Reason
dependency not pinned by hash detected -- score normalized to 4
Details
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
detected GitHub workflow tokens with excessive permissions
Details
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
Reason
project is not fuzzed
Details
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
Reason
22 existing vulnerabilities detected
Details
Score
Last Scanned on 2024-11-25
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More