1.1.0 • Published 9 months ago

@guoyunhe/retry v1.1.0

Weekly downloads
-
License
MIT
Repository
github
Last release
9 months ago

@guoyunhe/retry

Version Downloads Bundle size

a better retry function

Installation

npm install --save @guoyunhe/retry

Examples

import { retry } from '@guoyunhe/retry';

// By default, it will retry max. 5 times on any error.
await retry(() => fetch('/foobar.json'));

// You can define a different max. retry limit.
await retry(() => fetch('/foobar.json'), { retries: 666 });

// You can also control whether to retry by checking error type or message.
await retry(() => fetch('/foobar.json'), {
  shouldRetry: (e) => e.name === 'TypeError' && e.message === 'Failed to fetch',
});

// Retrying too often can crash systems. Use retryDelay to reduce retry frequence.
await retry(() => fetch('/foobar.json'), {
  // retryIndex starts from 1, not 0
  retryDelay: (retryIndex) => 1000 * Math.pow(retryIndex, 2);
});

Comparsion

PackageTSESMPromiseBundle Size
@guoyunhe/retrybundlephobia
@humanwhocodes/retrybundlephobia
p-retrybundlephobia
async-retrybundlephobia
retrybundlephobia
1.1.0

9 months ago

1.0.1

9 months ago

1.0.0

9 months ago