Miss any of our Open RFC calls?Watch the recordings here! »

ritry

0.1.0 • Public • Published

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

Install

npm i ritry

DownloadsWeekly Downloads

4

Version

0.1.0

License

MIT

Unpacked Size

177 kB

Total Files

7

Last publish

Collaborators

  • avatar