3.0.1 • Published 6 years ago

retry-times v3.0.1

Weekly downloads
6
License
MIT
Repository
github
Last release
6 years ago

Retry Times

Retry a task at most given times.

Deprecation

This package is deprecated to prefer the new retry-func package.

Installation

npm i retry-times --save

Usage

Retry a task directly

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)

Wrap a task with retry

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()

API

buildRetry

buildRetry(options) => retry(task) => Promise

buildWithRetry

buildWithRetry(options) => withRetry(task) => wrappedTask() => Promise

options

  • 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)

License

MIT

3.0.1

6 years ago

3.0.0

6 years ago

2.0.0

6 years ago

1.0.0

7 years ago