A utility that allows retrying a function with an exponential delay between attempts.
Installations
npm install exponential-backoff
Releases
Unable to fetch releases
Developer
coveo
Developer Guide
Module System
CommonJS
Min. Node Version
Typescript Support
Yes
Node Version
18.14.0
NPM Version
9.3.1
Statistics
359 Stars
93 Commits
26 Forks
10 Watching
2 Branches
4 Contributors
Updated on 14 Nov 2024
Languages
TypeScript (100%)
Total Downloads
Cumulative downloads
Total Downloads
492,434,121
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
Daily Downloads
Weekly Downloads
Monthly Downloads
Yearly Downloads
Dev Dependencies
8
exponential-backoff
A utility that allows retrying a function with an exponential delay between attempts.
Installation
npm i exponential-backoff
Usage
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. Iffalse
, 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
andnone
.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. Returningtrue
will retry the function as long as thenumOfAttempts
has not been exceeded. Returningfalse
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 thetimeMultiple
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
- Info: project has a license file: LICENSE:0
- Info: FSF or OSI recognized license: Apache License 2.0: LICENSE:0
Reason
dependency not pinned by hash detected -- score normalized to 4
Details
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/cd.yml:12: update your workflow using https://app.stepsecurity.io/secureworkflow/coveooss/exponential-backoff/cd.yml/master?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/ci.yml:13: update your workflow using https://app.stepsecurity.io/secureworkflow/coveooss/exponential-backoff/ci.yml/master?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/ci.yml:14: update your workflow using https://app.stepsecurity.io/secureworkflow/coveooss/exponential-backoff/ci.yml/master?enable=pin
- Info: 0 out of 3 GitHub-owned GitHubAction dependencies pinned
- Info: 2 out of 2 npmCommand dependencies pinned
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
- Warn: no topLevel permission defined: .github/workflows/cd.yml:1
- Warn: no topLevel permission defined: .github/workflows/ci.yml:1
- Info: topLevel 'contents' permission set to 'read': .github/workflows/dependency-review.yml:7
- Info: no jobLevel write permissions found
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
- Warn: no security policy file detected
- Warn: no security file to analyze
- Warn: no security file to analyze
- Warn: no security file to analyze
Reason
project is not fuzzed
Details
- Warn: no fuzzer integrations found
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
- Warn: 0 commits out of 30 are checked with a SAST tool
Reason
22 existing vulnerabilities detected
Details
- Warn: Project is vulnerable to: GHSA-67hx-6x53-jw92
- Warn: Project is vulnerable to: GHSA-grv7-fg5c-xmjg
- Warn: Project is vulnerable to: GHSA-3xgq-45jj-v275
- Warn: Project is vulnerable to: GHSA-gxpj-cx7g-858c
- Warn: Project is vulnerable to: GHSA-8r6j-v8pm-fqw3
- Warn: Project is vulnerable to: MAL-2023-462
- Warn: Project is vulnerable to: GHSA-qqgx-2p2h-9c37
- Warn: Project is vulnerable to: GHSA-952p-6rrq-rcjv
- Warn: Project is vulnerable to: GHSA-f8q6-p94x-37v3
- Warn: Project is vulnerable to: GHSA-vh95-rmgr-6w4m / GHSA-xvch-5gv4-984h
- Warn: Project is vulnerable to: GHSA-5fw9-fq32-wv5p
- Warn: Project is vulnerable to: GHSA-p8p7-x288-28g6
- Warn: Project is vulnerable to: GHSA-c2qf-rxjj-qqgw
- Warn: Project is vulnerable to: GHSA-3jfq-g458-7qm9
- Warn: Project is vulnerable to: GHSA-r628-mhmh-qjhw
- Warn: Project is vulnerable to: GHSA-9r2w-394v-53qc
- Warn: Project is vulnerable to: GHSA-5955-9wpr-37jh
- Warn: Project is vulnerable to: GHSA-qq89-hq3f-393p
- Warn: Project is vulnerable to: GHSA-f5x3-32g6-xq36
- Warn: Project is vulnerable to: GHSA-72xf-g2v4-qvf3
- Warn: Project is vulnerable to: GHSA-3h5v-q93c-6h6q
- Warn: Project is vulnerable to: GHSA-p9pc-299p-vxgp
Score
4.1
/10
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 MoreOther packages similar to 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)