1.0.0 • Published 5 years ago
retry-with-delay v1.0.0
retry-with-delay
Retry failed function call with delay
Installation
npm install retry-with-delay
yarn add retry-with-delay
Usage
import { retryWithDelay } from 'retry-with-delay'
const fn = async () => 'Hello'
const result = await retryWithDelay(fn, {
delaysMs: [100, 200, 300], // in case of error fn will be called 4 times, with specified delays between calls
})
API
retryWithDelay(fn: Function, options: Object) => Promise
fn
Function that should be retried in case of errors
options
Name | type | Default | Description |
---|---|---|---|
delaysMs | Array | [] | Represents delays between failed calls, e.g. [100, 200, 300] - in case of error fn will be called 4 times, with specified delays between calls |
onAttemptError | Function | () => null | Called on failed attempt with objects as an argument { error: Error, attempt: number, maxAttempts: number } |
onMaxAttemptsExceeded | Function | () => null | Called when max number of attempts is exceeded |
Testing
Clone the repository and execute:
yarn test
1.0.0
5 years ago