Wondering what’s next for npm?Check out our public roadmap! »

@ultraq/promise-utils

0.4.2 • Public • Published

promise-utils

Build Status Coverage Status npm Bundlephobia minified size

A collection of utilities for JavaScript promises.

Installation

Via npm:

npm install @ultraq/promise-utils

If targeting browsers that don't natively support Promise, a polyfill is required.

API

delay(doPromise, delayMs)

Add an artificial delay to the execution of a promise. Returns a promise that is resolved/rejected with the values of the underlying promise, executed after the initial delay has elapsed.

  • doPromise: A function which performs and returns the promise to be retried.
  • delayMs: Number of milliseconds to delay execution of the promise by.

pad(promise, padMs)

Causes promise resolution and rejection to take at least as long as the time specified. Returns a new promise that will be resolved or rejected after the padding time has elapsed.

  • promise: The Promise to pad out
  • padMs: Number of milliseconds to have promise padded out to, if it resolves or rejects too quickly.

retry(doPromise, numRetries, shouldRetry)

Retry a promise a specified number of times. Returns a promise that is resolved/rejected with the results of the underlying promise, or eventually rejected after the number of retries has been reached without success.

  • doPromise: A function which performs and returns the promise to be retried.
  • numRetries: The number of times a retry should be attempted.
  • shouldRetry: When the promise succeeds, this function is called with the result to determine whether or not the promise should be retried.

Install

npm i @ultraq/promise-utils

DownloadsWeekly Downloads

55

Version

0.4.2

License

Apache-2.0

Unpacked Size

36.6 kB

Total Files

10

Last publish

Collaborators

  • avatar