Skip to content

Allow custom retry interval#1161

Merged
megawac merged 4 commits intocaolan:masterfrom
aianus:custom_retry_interval
May 21, 2016
Merged

Allow custom retry interval#1161
megawac merged 4 commits intocaolan:masterfrom
aianus:custom_retry_interval

Conversation

@aianus
Copy link
Copy Markdown
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
Copy Markdown
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.

Comment thread lib/retry.js Outdated
};
}

function constantIntervalFunc(interval) {
Copy link
Copy Markdown
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
Copy Markdown
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.

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

acc.intervalFunc = (typeof t.interval === 'function' ?
Copy link
Copy Markdown
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
Copy Markdown
Collaborator

megawac commented May 21, 2016

Thanks!

@eexit
Copy link
Copy Markdown

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