Gathering detailed insights and metrics for async-retry-ng
Gathering detailed insights and metrics for async-retry-ng
Gathering detailed insights and metrics for async-retry-ng
Gathering detailed insights and metrics for async-retry-ng
npm install async-retry-ng
Typescript
Module System
Node Version
NPM Version
JavaScript (100%)
Total Downloads
51,349,137
Last Day
12,726
Last Week
71,331
Last Month
293,433
Last Year
3,704,060
NOASSERTION License
2 Stars
44 Commits
2 Watchers
1 Branches
1 Contributors
Updated on Dec 31, 2024
Minified
Minified + Gzipped
Latest Version
2.0.2
Package Id
async-retry-ng@2.0.2
Unpacked Size
12.17 kB
Size
4.86 kB
File Count
7
NPM Version
10.2.4
Node Version
20.11.1
Published on
Dec 31, 2024
Cumulative downloads
Total Downloads
Last Day
41.7%
12,726
Compared to previous day
Last Week
4.4%
71,331
Compared to previous week
Last Month
-5.7%
293,433
Compared to previous month
Last Year
-30.7%
3,704,060
Compared to previous year
4
Retrying made simple, easy, and async.
1// Packages 2const retry = require('async-retry-ng') 3const fetch = require('node-fetch') 4 5await retry(async bail => { 6 // if anything throws, we retry 7 const res = await fetch('https://google.com') 8 9 if (403 === res.status) { 10 // don't retry upon 403 11 bail(new Error('Unauthorized')) 12 return 13 } 14 15 const data = await res.text() 16 return data.substr(0, 500) 17}, { 18 retries: 5 19})
1retry(retrier : Function, opts : Object) => Promise
async
or not. In other words, it can be a function that returns a Promise
or a value.Function
you can invoke to abort the retrying (bail)Number
identifying the attempt. The absolute first attempt (before any retries) is 1
.opts
retries
: The maximum amount of times to retry the operation. Default is 10
.factor
: The exponential factor to use. Default is 2
.minTimeout
: The number of milliseconds before starting the first retry. Default is 1000
.maxTimeout
: The maximum number of milliseconds between two retries. Default is Infinity
.randomize
: Randomizes the timeouts by multiplying with a factor between 1
to 2
. Default is true
.onRetry
: an optional Function
that is invoked after a new retry is performed. It's passed the Error
that triggered it as a parameter.All time values are in milliseconds.
The formula used to calculate the individual timeouts is:
Math.min(random * minTimeout * Math.pow(factor, attempt), maxTimeout)
Have a look at this article for a better explanation of approach.
If you want to tune your factor
/ times
settings to attempt the last retry
after a certain amount of time, you can use wolfram alpha. For example in order
to tune for 10
attempts in 5 minutes
, you can use this equation:
Explaining the various values from left to right:
k = 0 ... 9
: The retries
value (10)1000
: The minTimeout
value in ms (1000)x^k
: No need to change this, x
will be your resulting factor5 * 60 * 1000
: The desired total amount of time for retrying in ms (5 minutes)To make this a little easier for you, use wolfram alpha to do the calculations:
http://www.wolframalpha.com/input/?i=Sum%5B1000*x^k%2C+{k%2C+0%2C+9}%5D+%3D+5+*+60+*+1000
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
no dangerous workflow patterns detected
Reason
license file detected
Details
Reason
1 existing vulnerabilities detected
Details
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
dependency not pinned by hash detected -- score normalized to 0
Details
Reason
Found 1/12 approved changesets -- 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
project is not fuzzed
Details
Reason
branch protection not enabled on development/release branches
Details
Reason
security policy file not detected
Details
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
Score
Last Scanned on 2025-04-28
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