Retry a task at most given times.
This package is deprecated to prefer the new retry-func package.
npm i retry-times --save
const {buildRetry} = require('retry-times')
// a task is any function without argument
const task = async () => {
...
}
const retry = buildRetry(3) // or buildRetry({times: 3})
const data = await retry(task)
const {buildWithRetry} = require('retry-times')
// a task is any function without argument
const task = async () => {
...
}
const withRetry = buildWithRetry(3) // or buildWithRetry({times: 3})
const taskWithRetry = withRetry(task)
const data = taskWithRetry()
buildRetry(options) => retry(task) => Promise
buildWithRetry(options) => withRetry(task) => wrappedTask() => Promise
- times - the task will run at most times
- onRetry -
onRetry(err, runCount)
, callback when the task is about to retry
The relations of run, onRetry, and runCount are as below:
run -> run -> run...
onRetry(err, runCount=1) onRetry(err, runCount=2)
MIT