Gathering detailed insights and metrics for back
Gathering detailed insights and metrics for back
Gathering detailed insights and metrics for back
Gathering detailed insights and metrics for back
npm install back
Typescript
Module System
Min. Node Version
Node Version
NPM Version
JavaScript (100%)
Total Downloads
0
Last Day
0
Last Week
0
Last Month
0
Last Year
0
MIT License
25 Stars
40 Commits
6 Forks
3 Watchers
1 Branches
4 Contributors
Updated on Jun 24, 2024
Latest Version
1.0.2
Package Id
back@1.0.2
Size
3.88 kB
NPM Version
3.10.10
Node Version
6.10.0
Published on
Sep 01, 2017
Cumulative downloads
Total Downloads
Last Day
0%
NaN
Compared to previous day
Last Week
0%
NaN
Compared to previous week
Last Month
0%
NaN
Compared to previous month
Last Year
0%
NaN
Compared to previous year
A simple module to be used for creating exponentially weighted backoff attempts. Originally extracted from Primus.
NOTICE
If you were a pre-1.0.0 back
user, the API has changed to what is found below.
If you do not like this slightly different abstraction and would prefer the
former, slightly simpler API, it is still available with require('back/reconnect')
.
The API change thanks to a contribution from @Raynos makes things simpler as you don't have to manage the copying of the options object yourself in order to handle repeated backoff cases.
1var http = require('http'); 2var back = require('back'); 3// 4// Options to use for backoff 5// 6// Remark: This object is modified so it should be cloned if you are dealing 7// with independent backoff attempts and want to use these values as a base. 8// 9var options = { 10 retries: 3, 11 minDelay: 1000, // Defaults to 500ms 12 maxDelay: 10000, // Defaults to infinity 13 // The following option is shown with its default value but you will most 14 // likely never define it as it creates the exponential curve. 15 factor: 2, 16}; 17 18// Where we will store the backoff instance during a particular backoff attempt 19var attempt; 20 21function retry(err) { 22 var back = attempt || (attempt = new Back(options)); 23 return back.backoff(function (fail) { 24 if (fail) { 25 // Oh noez we never reconnect :( 26 console.error('Retry failed with ' + err.message); 27 process.exit(1); 28 } 29 // 30 // Remark: .attempt and .timeout are added to this object internally 31 // 32 console.log('Retry attempt # ' + back.settings.attempt + 33 ' being made after ' + back.settings.timeout + 'ms'); 34 request(); 35 }); 36} 37 38function request() { 39 http.get('http://localhost:9000', function (res) { 40 console.log('Successful Response that will not happen!'); 41 // 42 // If we succeeded, we would set the current to null so the next error 43 // generates a new instance. 44 // 45 attempt = null; 46 }).on('error', retry); 47} 48 49request();
var back = new Back(backoffOpts);
The Back
constructor function takes your backoff options and saves them as
settings
in the internal state of the back
object.
back.backoff(callback)
The back
instance has a backoff
method that takes a callback
that is
executed after a setTimeout
. The timeout is what is based on an exponential
backoff of course!
It will repeatedly all this callback based on the backoff options you passed to
the back instance until it exhausts its efforts. When it has exhausted its
attempts, it will return an error as the first argument to the callback.
back.close()
Clear backoff timer in cases where you want to dispose of the instance before the callback
is executed.
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
0 existing vulnerabilities detected
Reason
license file detected
Details
Reason
Found 3/28 approved changesets -- score normalized to 1
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- 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 2025-07-07
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