Skip to content

Commit

Permalink
fix: retry() can no longer be called with an interval of Infinity.
Browse files Browse the repository at this point in the history
Passing Infinity causes node 10 to print a warning, as internally it uses a 32 bit integer.

BREAKING CHANGE: `retry()` can no longer be called with an interval of Infinity.
  • Loading branch information
Jason Walton committed Oct 23, 2018
1 parent 3b71c01 commit e9a39aa
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
3 changes: 3 additions & 0 deletions src/index.js
Expand Up @@ -242,6 +242,9 @@ export function retry(options, fn) {
}

if (options.interval) {
if(options.interval === Infinity) {
return Promise.reject(new Error(`'interval' may not be Infinity`));
}
interval = +options.interval;
}
} else if (options) {
Expand Down
12 changes: 10 additions & 2 deletions test/retry.js
Expand Up @@ -42,14 +42,20 @@ describe('retry', () => {
{options: {times: 5.4}, msg: 'just times'},
{options: {times: Infinity}, msg: 'times = Infinity'},
{options: {}, msg: 'neither times nor interval'},
{options: {interval: Infinity}, msg: 'Should accept Infinity interval'}
].forEach((args) => {
it(`should accept first argument as an options hash with ${args.msg}`, () => {
let retry = promiseTools.retry(args.options, getTest(5));
return expect(retry).to.eventually.equal(5);
});
});

it('should error if interval is infinity', () => {
return expect(
promiseTools.retry({times: 5, interval: Infinity}, getTest(1))
).to.eventually.be.rejectedWith(`'interval' may not be Infinity`);
})


it('should call the default 5 times with no options provided', () => {
let retry = promiseTools.retry(getTest(5));
return expect(retry).to.eventually.equal(5);
Expand All @@ -61,7 +67,9 @@ describe('retry', () => {
})

it('should return an error with invalid options argument', () => {
return expect(promiseTools.retry({times: "foo"}, getTest(1))).to.eventually.be.rejectedWith('Unsupported argument type for \'times\': string');
return expect(
promiseTools.retry({times: "foo"}, getTest(1))
).to.eventually.be.rejectedWith('Unsupported argument type for \'times\': string');
});

it('should reject when called with nothing', () => {
Expand Down

0 comments on commit e9a39aa

Please sign in to comment.