Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow custom retry interval #1161

Merged
merged 4 commits into from May 21, 2016
Merged

Allow custom retry interval #1161

merged 4 commits into from May 21, 2016

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.

@@ -129,4 +133,10 @@ export default function retry(times, task, callback) {
}, interval);
};
}

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.

};

function parseTimes(acc, t) {
if (typeof t === 'object') {
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.

None yet

4 participants