Meet npm Pro: unlimited public & private packages + package-based permissions.Learn more »

ts-retry

1.0.13 • Public • Published

ts-retry

A little retry tool in javascript/typescript for node.

How to:

  • to retry something: await retry(()=> {/* do something */}, {delay:100,maxTry:5})
  • to retry something async : await retryAsync(async ()=> {/* do something */}, {delay:100,maxTry:5})

Above examples make up to 5 attempts, waiting 100ms between each try.

API

  • retry(fn, retryOptions): call repeteadly fn until fn does not throw and exception. Stop after retryOptions.maxTry count. Between each call wait retryOptions.delay milliseconds. if stop to call fn after retryOptions.maxTry, throws fn execption, otherwise returns fn return value.
  • retryAsync(fn, retryOptions): same as retry, except fn is an asynchronous function.
  • retryOptions:
    • maxTry maximum calls to fn.
    • delay: delay between each call (in milliseconds).

Install

npm i ts-retry

DownloadsWeekly Downloads

61

Version

1.0.13

License

MIT

Unpacked Size

10.9 kB

Total Files

15

Last publish

Collaborators

  • avatar