Skip to content

Conversation

aianus
Copy link
Contributor

@aianus aianus commented May 18, 2016

Allow interval to be specified as a function(retryCount) : int so users can have exponential backoffs, etc.
#1001

@aianus
Copy link
Contributor Author

aianus commented May 18, 2016

Needed exponential backoff for a project and figured I'd kick my implementation upstream in case anyone finds it useful.

lib/retry.js Outdated
};
}

function constantIntervalFunc(interval) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you import constant from 'lodash/constant' instead

@aearly
Copy link
Collaborator

aearly commented May 18, 2016

This feature also needs to be mentioned in the docs -- also perhaps with an example on how to do exponential back-off, or use a pre-baked array of intervals.

lib/retry.js Outdated
acc.times = +t.times || DEFAULT_TIMES;
acc.interval = +t.interval || DEFAULT_INTERVAL;

acc.intervalFunc = (typeof t.interval === 'function' ?
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

extraneous bracket.

acc.intervalFunc = typeof t.interval === 'function' ?
                t.interval :
                constant(+t.interval || DEFAULT_INTERVAL);

Otherwise looks good to me and +1

@megawac megawac merged commit 22d13bf into caolan:master May 21, 2016
@megawac
Copy link
Collaborator

megawac commented May 21, 2016

Thanks!

@eexit
Copy link

eexit commented Jun 10, 2016

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants