Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

retry-request

Package Overview
Dependencies
Maintainers
1
Versions
40
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

retry-request - npm Package Compare versions

Comparing version 1.0.0 to 1.1.0

38

index.js

@@ -17,3 +17,3 @@ 'use strict';

module.exports = function (requestOpts, opts, callback) {
function retryRequest(requestOpts, opts, callback) {
var streamMode = typeof arguments[arguments.length - 1] !== 'function';

@@ -37,11 +37,19 @@

var retryStream = through();
var numAttempts = 0;
var retryStream;
var requestStream;
var cacheStream;
var cachedEvents = {};
var attempts = 0;
if (streamMode) {
retryStream = through();
}
makeRequest();
if (streamMode) {
return retryStream;
}
function resetStreams() {
cachedEvents = {};
cacheStream = null;

@@ -52,4 +60,4 @@ requestStream.abort();

function attempt() {
attempts++;
function makeRequest() {
numAttempts++;

@@ -83,3 +91,3 @@ if (streamMode) {

// Send the response to see if we should try again.
if (attempts <= opts.retries && opts.shouldRetryFn(response)) {
if (numAttempts <= opts.retries && opts.shouldRetryFn(response)) {
if (streamMode) {

@@ -89,4 +97,3 @@ resetStreams();

attempt();
setTimeout(makeRequest, getNextRetryDelay(numAttempts));
return;

@@ -106,5 +113,10 @@ }

}
}
attempt();
return retryStream;
};
module.exports = retryRequest;
function getNextRetryDelay(retryNumber) {
return (Math.pow(2, retryNumber) * 1000) + Math.floor(Math.random() * 1000);
}
module.exports.getNextRetryDelay = getNextRetryDelay;
{
"name": "retry-request",
"version": "1.0.0",
"version": "1.1.0",
"description": "Retry a request.",
"main": "index.js",
"scripts": {
"test": "mocha --timeout 5000"
"test": "mocha --timeout 10000"
},

@@ -9,0 +9,0 @@ "files": [

# retry-request
> Retry a [request][request].
> Retry a [request][request] with built-in [exponential backoff](https://developers.google.com/analytics/devguides/reporting/core/v3/coreErrors#backoff).

@@ -98,3 +98,3 @@ ## Use

retryRequest(urlThatReturns404, function (err, resp, body) {
retryRequest(urlThatReturns404, opts, function (err, resp, body) {
// Your provided `request` instance was used.

@@ -101,0 +101,0 @@ });

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc