diff options
Diffstat (limited to 'lib/retry.js')
-rw-r--r-- | lib/retry.js | 17 |
1 files changed, 5 insertions, 12 deletions
diff --git a/lib/retry.js b/lib/retry.js index 4029e10..99040e8 100644 --- a/lib/retry.js +++ b/lib/retry.js @@ -2,6 +2,7 @@ import series from './series'; import noop from 'lodash/noop'; +import constant from 'lodash/constant'; /** * Attempts to get a successful response from `task` no more than `times` times @@ -66,18 +67,16 @@ export default function retry(times, task, callback) { var opts = { times: DEFAULT_TIMES, - intervalFunc: constantIntervalFunc(DEFAULT_INTERVAL) + intervalFunc: constant(DEFAULT_INTERVAL) }; function parseTimes(acc, t) { if (typeof t === 'object') { acc.times = +t.times || DEFAULT_TIMES; - if (typeof t.interval === 'function') { - acc.intervalFunc = t.interval; - } else { - acc.intervalFunc = constantIntervalFunc(+t.interval || DEFAULT_INTERVAL); - } + acc.intervalFunc = typeof t.interval === 'function' ? + t.interval : + constant(+t.interval || DEFAULT_INTERVAL); } else if (typeof t === 'number' || typeof t === 'string') { acc.times = +t || DEFAULT_TIMES; } else { @@ -133,10 +132,4 @@ export default function retry(times, task, callback) { }, interval); }; } - - function constantIntervalFunc(interval) { - return function() { - return interval; - }; - } } |