Comparing version 5.1.0 to 5.2.0
22
index.js
@@ -22,7 +22,2 @@ 'use strict'; | ||
function backoff(iter) { | ||
var noise = Math.random() * 1000; | ||
return (1 << iter) * 1000 + noise; | ||
} | ||
function requestAsEventEmitter(opts) { | ||
@@ -65,4 +60,5 @@ opts = opts || {}; | ||
req.once('error', function (err) { | ||
if (retryCount < opts.retries) { | ||
setTimeout(get, backoff(retryCount++), opts); | ||
var backoff = opts.retries(++retryCount); | ||
if (backoff) { | ||
setTimeout(get, backoff, opts); | ||
return; | ||
@@ -275,2 +271,14 @@ } | ||
if (typeof opts.retries !== 'function') { | ||
var retries = opts.retries; | ||
opts.retries = function backoff(iter) { | ||
if (iter > retries) { | ||
return 0; | ||
} | ||
var noise = Math.random() * 100; | ||
return (1 << iter) * 1000 + noise; | ||
}; | ||
} | ||
return opts; | ||
@@ -277,0 +285,0 @@ } |
{ | ||
"name": "got", | ||
"version": "5.1.0", | ||
"version": "5.2.0", | ||
"description": "Simplified HTTP/HTTPS requests", | ||
@@ -57,3 +57,3 @@ "license": "MIT", | ||
"parse-json": "^2.1.0", | ||
"pinkie-promise": "^1.0.0", | ||
"pinkie-promise": "^2.0.0", | ||
"read-all-stream": "^3.0.0", | ||
@@ -65,3 +65,3 @@ "timed-out": "^2.0.0", | ||
"devDependencies": { | ||
"ava": "^0.3.0", | ||
"ava": "^0.5.0", | ||
"coveralls": "^2.11.4", | ||
@@ -68,0 +68,0 @@ "get-port": "^2.0.0", |
@@ -11,3 +11,3 @@ <h1 align="center"> | ||
[![Build Status](https://travis-ci.org/sindresorhus/got.svg?branch=master)](https://travis-ci.org/sindresorhus/got) [![Coverage Status](https://coveralls.io/repos/sindresorhus/got/badge.svg?service=github&branch=master)](https://coveralls.io/github/sindresorhus/got?branch=master) | ||
[![Build Status](https://travis-ci.org/sindresorhus/got.svg?branch=master)](https://travis-ci.org/sindresorhus/got) [![Coverage Status](https://coveralls.io/repos/sindresorhus/got/badge.svg?service=github&branch=master)](https://coveralls.io/github/sindresorhus/got?branch=master) [![Downloads](https://img.shields.io/npm/dm/got.svg?style=flat)](https://npmjs.com/got) | ||
@@ -122,7 +122,8 @@ A nicer interface to the built-in [`http`](http://nodejs.org/api/http.html) module. | ||
Type: `number` | ||
Type: `number`, `function` | ||
Default: `5` | ||
Number of request retries when network errors happens. | ||
Number of request retries when network errors happens. Delays between retries counts with function `Math.pow(2, retry) + Math.random() * 100`, where `retry` is attempt number (starts from 0). | ||
Option accepts `function` with `retry` argument that must return delay in milliseconds (`0` return value cancels retry). | ||
@@ -129,0 +130,0 @@ ##### callback(error, data, response) |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
19341
290
291
- Removedpinkie@1.0.0(transitive)
- Removedpinkie-promise@1.0.0(transitive)
Updatedpinkie-promise@^2.0.0