Socket
Socket
Sign inDemoInstall

promise-retry

Package Overview
Dependencies
3
Maintainers
2
Versions
17
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 0.2.9 to 1.0.0

6

index.js

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

var retry = require('retry');
var Promise = require('bluebird');
var promiseTry = require('promise-try');

@@ -31,3 +31,3 @@ var hasOwn = Object.prototype.hasOwnProperty;

promise = Promise.try(function () {
promise = promiseTry(function () {
return fn(function (err) {

@@ -44,3 +44,3 @@ if (isRetryError(err)) {

promise.done(resolve, function (err) {
promise.then(resolve, function (err) {
if (isRetryError(err)) {

@@ -47,0 +47,0 @@ err = err.retried;

{
"name": "promise-retry",
"version": "0.2.9",
"version": "1.0.0",
"description": "Retries a function that returns a promise, leveraging the power of the retry module.",

@@ -20,3 +20,2 @@ "main": "index.js",

"backoff",
"bluebird",
"repeat",

@@ -29,9 +28,10 @@ "replay"

"expect.js": "^0.3.1",
"mocha": "^2.1.0"
"mocha": "^2.3.4",
"sleep-promise": "^1.0.0"
},
"dependencies": {
"bluebird": "^2.6.2",
"err-code": "^0.1.2",
"retry": "^0.6.1"
"err-code": "^1.0.0",
"promise-try": "^1.0.1",
"retry": "^0.8.0"
}
}

@@ -1,3 +0,15 @@

# node-promise-retry [![Build Status](https://travis-ci.org/IndigoUnited/node-promise-retry.svg?branch=master)](https://travis-ci.org/IndigoUnited/node-promise-retry)
# node-promise-retry
[![NPM version][npm-image]][npm-url] [![Downloads][downloads-image]][npm-url] [![Build Status][travis-image]][travis-url] [![Dependency status][david-dm-image]][david-dm-url] [![Dev Dependency status][david-dm-dev-image]][david-dm-dev-url]
[npm-url]:https://npmjs.org/package/promise-retry
[downloads-image]:http://img.shields.io/npm/dm/promise-retry.svg
[npm-image]:http://img.shields.io/npm/v/promise-retry.svg
[travis-url]:https://travis-ci.org/IndigoUnited/node-promise-retry
[travis-image]:http://img.shields.io/travis/IndigoUnited/node-promise-retry.svg
[david-dm-url]:https://david-dm.org/IndigoUnited/node-promise-retry
[david-dm-image]:https://img.shields.io/david/IndigoUnited/node-promise-retry.svg
[david-dm-dev-url]:https://david-dm.org/IndigoUnited/node-promise-retry#info=devDependencies
[david-dm-dev-image]:https://img.shields.io/david/dev/IndigoUnited/node-promise-retry.svg
Retries a function that returns a promise, leveraging the power of the [retry](https://github.com/tim-kos/node-retry) module to the promises world.

@@ -4,0 +16,0 @@

'use strict';
var expect = require('expect.js');
var Promise = require('bluebird');
var promiseRetry = require('../');
var promiseDelay = require('sleep-promise');
describe('promise-retry', function () {
it('should call fn again if retry was called', function (done) {
it('should call fn again if retry was called', function () {
var count = 0;
promiseRetry(function (retry) {
return promiseRetry(function (retry) {
count += 1;
return Promise.delay(10)
return promiseDelay(10)
.then(function () {

@@ -28,14 +28,13 @@ if (count <= 2) {

throw new Error('should not fail');
})
.done(done, done);
});
});
it('should call fn with the attempt number', function (done) {
it('should call fn with the attempt number', function () {
var count = 0;
promiseRetry(function (retry, number) {
return promiseRetry(function (retry, number) {
count += 1;
expect(count).to.equal(number);
return Promise.delay(10)
return promiseDelay(10)
.then(function () {

@@ -54,14 +53,15 @@ if (count <= 2) {

throw new Error('should not fail');
})
.done(done, done);
});
});
it('should not retry on fulfillment if retry was not called', function (done) {
it('should not retry on fulfillment if retry was not called', function () {
var count = 0;
promiseRetry(function () {
return promiseRetry(function () {
count += 1;
return Promise.delay(10)
.thenReturn('final');
return promiseDelay(10)
.then(function () {
return 'final';
});
})

@@ -73,14 +73,15 @@ .then(function (value) {

throw new Error('should not fail');
})
.done(done, done);
});
});
it('should not retry on rejection if retry was not called', function (done) {
it('should not retry on rejection if retry was not called', function () {
var count = 0;
promiseRetry(function () {
return promiseRetry(function () {
count += 1;
return Promise.delay(10)
.thenThrow(new Error('foo'));
return promiseDelay(10)
.then(function () {
throw new Error('foo');
});
})

@@ -92,14 +93,15 @@ .then(function () {

expect(count).to.be(1);
})
.done(done, done);
});
});
it('should not retry on rejection if nr of retries is 0', function (done) {
it('should not retry on rejection if nr of retries is 0', function () {
var count = 0;
promiseRetry(function (retry) {
return promiseRetry(function (retry) {
count += 1;
return Promise.delay(10)
.thenThrow(new Error('foo'))
return promiseDelay(10)
.then(function () {
throw new Error('foo');
})
.catch(retry);

@@ -112,14 +114,15 @@ }, { retries : 0 })

expect(count).to.be(1);
})
.done(done, done);
});
});
it('should reject the promise if the retries were exceeded', function (done) {
it('should reject the promise if the retries were exceeded', function () {
var count = 0;
promiseRetry(function (retry) {
return promiseRetry(function (retry) {
count += 1;
return Promise.delay(10)
.thenThrow(new Error('foo'))
return promiseDelay(10)
.then(function () {
throw new Error('foo');
})
.catch(retry);

@@ -132,11 +135,10 @@ }, { retries: 2, factor: 1 })

expect(count).to.be(3);
})
.done(done, done);
});
});
it('should pass options to the underlying retry module', function (done) {
it('should pass options to the underlying retry module', function () {
var count = 0;
promiseRetry(function (retry) {
return Promise.delay(10)
return promiseRetry(function (retry) {
return promiseDelay(10)
.then(function () {

@@ -155,8 +157,7 @@ if (count < 2) {

expect(err.message).to.be('foo');
})
.done(done, done);
});
});
it('should convert direct fulfillments into promises', function (done) {
promiseRetry(function () {
it('should convert direct fulfillments into promises', function () {
return promiseRetry(function () {
return 'final';

@@ -168,7 +169,6 @@ }, { factor: 1 })

throw new Error('should not fail');
})
.done(done, done);
});
});
it('should convert direct rejections into promises', function (done) {
it('should convert direct rejections into promises', function () {
promiseRetry(function () {

@@ -181,8 +181,7 @@ throw new Error('foo');

expect(err.message).to.be('foo');
})
.done(done, done);
});
});
it('should not crash on undefined rejections', function (done) {
promiseRetry(function () {
it('should not crash on undefined rejections', function () {
return promiseRetry(function () {
throw undefined;

@@ -204,13 +203,12 @@ }, { retries: 1, factor: 1 })

expect(err).to.be(undefined);
})
.done(done, done);
});
});
it('should retry if retry() was called with undefined', function (done) {
it('should retry if retry() was called with undefined', function () {
var count = 0;
promiseRetry(function (retry) {
return promiseRetry(function (retry) {
count += 1;
return Promise.delay(10)
return promiseDelay(10)
.then(function () {

@@ -229,13 +227,12 @@ if (count <= 2) {

throw new Error('should not fail');
})
.done(done, done);
});
});
it('should work with several retries in the same chain', function (done) {
it('should work with several retries in the same chain', function () {
var count = 0;
promiseRetry(function (retry) {
return promiseRetry(function (retry) {
count += 1;
return Promise.delay(10)
return promiseDelay(10)
.then(function () {

@@ -253,13 +250,12 @@ retry(new Error('foo'));

expect(count).to.be(2);
})
.done(done, done);
});
});
it('should allow options to be passed first', function (done) {
it('should allow options to be passed first', function () {
var count = 0;
promiseRetry({ factor: 1 }, function (retry) {
return promiseRetry({ factor: 1 }, function (retry) {
count += 1;
return Promise.delay(10)
return promiseDelay(10)
.then(function () {

@@ -277,4 +273,4 @@ if (count <= 2) {

throw new Error('should not fail');
}).done(done, done);
});
});
});

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with โšก๏ธ by Socket Inc