-
Notifications
You must be signed in to change notification settings - Fork 2.4k
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
Conversation
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) { |
There was a problem hiding this comment.
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
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' ? |
There was a problem hiding this comment.
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
Thanks! |
Thanks! |
Allow interval to be specified as a function(retryCount) : int so users can have exponential backoffs, etc.
#1001