promise-retry
Advanced tools
Comparing version 0.2.6 to 0.2.7
@@ -11,3 +11,3 @@ 'use strict'; | ||
return new Promise(function (resolve, reject) { | ||
operation.attempt(function () { | ||
operation.attempt(function (number) { | ||
var promise; | ||
@@ -24,3 +24,3 @@ | ||
}); | ||
}); | ||
}, number); | ||
}); | ||
@@ -27,0 +27,0 @@ |
{ | ||
"name": "promise-retry", | ||
"version": "0.2.6", | ||
"version": "0.2.7", | ||
"description": "Retries a function that returns a promise, leveraging the power of the retry module.", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -38,3 +38,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) | ||
// Simple example | ||
promiseRetry(function (retry) { | ||
promiseRetry(function (retry, number) { | ||
console.log('attempt number', number); | ||
return doSomething() | ||
@@ -50,3 +52,5 @@ .catch(retry); | ||
// Conditional example | ||
promiseRetry(function (retry) { | ||
promiseRetry(function (retry, number) { | ||
console.log('attempt number', number); | ||
return doSomething() | ||
@@ -53,0 +57,0 @@ .catch(function (err) { |
@@ -32,2 +32,27 @@ 'use strict'; | ||
it('should call fn with the attempt number', function (done) { | ||
var count = 0; | ||
promiseRetry(function (retry, number) { | ||
count += 1; | ||
expect(count).to.equal(number); | ||
return Promise.delay(10) | ||
.then(function () { | ||
if (count <= 2) { | ||
retry(new Error('foo')); | ||
} | ||
return 'final'; | ||
}); | ||
}, { factor: 1 }) | ||
.then(function (value) { | ||
expect(value).to.be('final'); | ||
expect(count).to.be(3); | ||
}, function () { | ||
throw new Error('should not fail'); | ||
}) | ||
.done(done, done); | ||
}); | ||
it('should not retry on fulfillment if retry was not called', function (done) { | ||
@@ -34,0 +59,0 @@ var count = 0; |
13119
227
79