1.0.0 • Published 5 years ago

retry-with-delay v1.0.0

Weekly downloads
-
License
MIT
Repository
github
Last release
5 years ago

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

NametypeDefaultDescription
delaysMsArray[]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
onAttemptErrorFunction() => nullCalled on failed attempt with objects as an argument { error: Error, attempt: number, maxAttempts: number }
onMaxAttemptsExceededFunction() => nullCalled when max number of attempts is exceeded

Testing

Clone the repository and execute:

yarn test
1.0.0

5 years ago