JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 23
  • Score
    100M100P100Q50439F
  • License MIT

Package Exports

  • @parzh/retryable

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (@parzh/retryable) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

@parzh/retryable

Convenience function to retry executing an action, untill a desired result is achieved

Installation

npm i @parzh/retryable
yarn add @parzh/retryable

Usage

const content = await retryable((resolve, reject, retry) => {
  fs.readfile("/path/to/file", (err, data) => {
    if (!err)
      // no errors occured
      return resolve(data);

    // otherwise: an error occured

    if (retry.count >= RETRY_LIMIT)
      if (SHOULD_IGNORE_RETRY_LIMIT)
        // retry limit reached
        // retry limit is ignored
        retry.setCount(0);

      else
        // retry limit reached
        // retry limit is respected
        return reject("Retry limit reached!");

    // otherwise: retry limit is not reached or ignored

    if (SHOULD_RETRY_IMMEDIATELY)
      // retrying immediately
      retry();

    else
      // retrying after {2^retries × 100} milliseconds
      retry.after(2 ** retry.count * 100);
  });
});