Gathering detailed insights and metrics for re
Gathering detailed insights and metrics for re
Gathering detailed insights and metrics for re
Gathering detailed insights and metrics for re
npm install re
Typescript
Module System
Min. Node Version
Node Version
NPM Version
77.2
Supply Chain
99
Quality
75.8
Maintenance
100
Vulnerability
100
License
Updated on 03 Oct 2023
Minified
Minified + Gzipped
JavaScript (79.24%)
HTML (20.76%)
Cumulative downloads
Total Downloads
Last day
22.4%
Compared to previous day
Last week
-4.2%
Compared to previous week
Last month
-9.1%
Compared to previous month
Last year
4.5%
Compared to previous year
No dependencies detected.
Do it again, if it doesn't work the first time. Supports various configurable retry strategies, including: constant, exponential backoff and linear backoff.
Functions are styled to match the simplicity and ease of use found in the async library.
npm install re
1var Re = require('re'), 2 re = new Re(); 3 4re.try(repeatMe, doMeAtTheEnd); 5 6var repeatMe = function(retryCount, done){ 7 if(retryCount < 2) done(new Error("Not there yet!")); 8 else done(null, retryCount); 9}; 10 11var doMeAtTheEnd = function(err, retryCount){ 12 console.log("It took this many tries: " + retryCount); 13};
Tested in recent versions of Internet Explorer, Firefox and Chrome. Usage:
1<script type="text/javascript" src="re.js"></script> 2<script type="text/javascript"> 3 var re = new Re(); 4 5 re.try(repeatMe, doMeAtTheEnd); 6 7 // repeatMe and doMeAtTheEnd are exactly as above 8 9</script>
Try it in your browser with this test: test/test.html or play with the test in this fiddle: re-fiddle (these pages don't work in IE, because it's recently gone from lax to pedantic).
If you like the defaults, call it like this:
1var Re = require('re'), 2 re = new Re(); 3 4re.try(function(retryCount, done){ 5 if(retryCount < 2) done(new Error("Not there yet!")); 6 else done(null, retryCount); 7 }, 8 function(err, retryCount){ 9 console.log("It took this many retries: " + retryCount); 10});
The re.try
function takes two arguments, a function to call until it works
(or we run out of retries) and a function to call when it finally succeeds (or
we fail too many times).
As the name suggests we automatically wrap your function in a standard try
block and, if an exception occurs, call it again according to the retry schedule.
This first function passed to re.try
should take 2 arguments like this:
1function operation(retryCount, done)
The retryCount
argument is the number of the current retry. It'll be zero the first time
and get bigger every time.
The done
argument is a function to call when you've completed your operation.
If you encounter an error condition, pass in the err
object
as the first argument. If you don't encounter an error, pass in a falsy first
argument (null works). If you give us a falsy error and no exception happens,
we call your callback with all the arguments passed into this function.
The second function passed to re.try
can take as many arguments as you like but
should always start with an error parameter. This will be falsy, if no error happens.
The re.do
function is like re.try
except it doesn't wrap your operation in
a try...catch
.
The default options look like this:
1var options = { 2 retries : 10, 3 strategy : { 4 "type": Re.STRATEGIES.EXPONENTIAL, 5 "initial":100, 6 "base":2 7 } 8}
You pass this options object into the Re
constructor.
1var Re = require('re'), 2 re = new Re(options);
This gives you 10 retries and an exponential backoff strategy with the following progression (in milliseconds): 100, 200, 400, 800, 1600, 3200, 6400, 12800, 25600, 51200
The following will retry every 400 milliseconds:
1{"type": Re.STRATEGIES.CONSTANT, "initial": 400}
The following will give a linear backoff strategy that has the following progression (when paired with retries: 10
) : 200, 400, 600, 800, 1000, 1200, 1400, 1600, 1800, 1800
1{"type": Re.STRATEGIES.LINEAR, "initial": 200, "max":1800}
Both progressive strategies accept the max
option. All strategies also accept a
rand
option. This is a Boolean
that adds a random multiplier between 1 and 2.
This makes them act like the tradition backoff function. This option is set to false
by default.
Test coverage is good and expanding. We use mocha.
The traditional exponential backoff function is described here:
Exponential Backoff in Distributed Systems.
This is equivalent to our exponential backoff function with the rand
option set to true
.
Our formula for exponential backoff looks something like this, when using all the options:
1return Math.min(random * initial * Math.pow(base, retry), max);
Where random
is a random number in the half-open interval [1, 2). When randomness is turned off,
the value of this variable is always 1.
If you don't specify the max
option, the formula looks like this:
1return random * initial * Math.pow(base, retry);
I'm shamelessly stealing the following link from node-retry
just because it's fun for nerdy math people to play with.
You can use it to calculate the exact value you need for the base
option so that all
retry intervals sum to a desired amount: Wolfram Alpha.
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
0 existing vulnerabilities detected
Reason
license file detected
Details
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
Found 2/29 approved changesets -- score normalized to 0
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
branch protection not enabled on development/release branches
Details
Reason
SAST tool is not run on all commits -- score normalized to 0
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