0.1.0 • Published 5 years ago

ritry v0.1.0

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

ritry

Install

$ npm install --save ritry

Usage

The following code throws an error after 4 retries.

import { ritry } from 'ritry'

function promiseFunction() {
  return new Promise((_, reject) => {
    setTimeout(() => reject(new Error('fail')), 500)
  })
}

ritry(promiseFunction, { retry: 4 }).catch((err) => {
  console.error(err)
})

you can gradually increase the duration.

import { ritry } from 'ritry'

function promiseFunction({ retryCount }) {
  const duration = 1000 + retryCount * 200
  return new Promise((_, reject) => {
    setTimeout(() => reject(new Error('fail')), duration)
  })
}

ritry(promiseFunction, { retry: 4 }).catch((err) => {
  console.error(err)
})
declare type Callback<T> = () => Promise<T>;
declare type Options = {
  retry?: number;
};
export declare function ritry<T>(callback: Callback<T>, options?: Options): Promise<T>;

Options

retry

default: 1
You can change the number of retries

License

MIT

0.1.0

5 years ago

0.0.4

5 years ago

0.0.3

5 years ago

0.0.2

5 years ago

0.0.1

5 years ago