Get unlimited public & private packages + package-based permissions with npm Pro.Get started »

ts-retry

1.1.0 • Public • Published

ts-retry

A little retry tool in javascript/typescript for node and for browser.

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})
  • to wait 1OOms of milliseconds: await wait(100)

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

168

Version

1.1.0

License

MIT

Unpacked Size

11.1 kB

Total Files

11

Last publish

Collaborators

  • avatar