promise-retry
Advanced tools
Comparing version 0.2.8 to 0.2.9
12
index.js
@@ -14,4 +14,14 @@ 'use strict'; | ||
function promiseRetry(fn, options) { | ||
var operation = retry.operation(options); | ||
var temp; | ||
var operation; | ||
if (typeof fn === 'object' && typeof options === 'function') { | ||
// Swap options and fn when using alternate signature (options, fn) | ||
temp = options; | ||
options = fn; | ||
fn = temp; | ||
} | ||
operation = retry.operation(options); | ||
return new Promise(function (resolve, reject) { | ||
@@ -18,0 +28,0 @@ operation.attempt(function (number) { |
{ | ||
"name": "promise-retry", | ||
"version": "0.2.8", | ||
"version": "0.2.9", | ||
"description": "Retries a function that returns a promise, leveraging the power of the retry module.", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -33,3 +33,5 @@ # node-promise-retry [![Build Status](https://travis-ci.org/IndigoUnited/node-promise-retry.svg?branch=master)](https://travis-ci.org/IndigoUnited/node-promise-retry) | ||
If you prefer, you can pass the options first using the alternative function signature `promiseRetry([options], fn)`. | ||
## Example | ||
```js | ||
@@ -36,0 +38,0 @@ var promiseRetry = require('promise-retry'); |
@@ -245,2 +245,24 @@ 'use strict'; | ||
}); | ||
it('should allow options to be passed first', function (done) { | ||
var count = 0; | ||
promiseRetry({ factor: 1 }, function (retry) { | ||
count += 1; | ||
return Promise.delay(10) | ||
.then(function () { | ||
if (count <= 2) { | ||
retry(new Error('foo')); | ||
} | ||
return 'final'; | ||
}); | ||
}).then(function (value) { | ||
expect(value).to.be('final'); | ||
expect(count).to.be(3); | ||
}, function () { | ||
throw new Error('should not fail'); | ||
}).done(done, done); | ||
}); | ||
}); |
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
14785
273
81
0