index

Wraps a Promise implementation to enable the following behaviors:

Static Changes

  • Promise.timeout created.
  • Promise.unwrap created.
  • Promise.apply/fapply created.
  • Promise.call/fcall/try/attempt created.
  • Promise.config.setErrorHandler created.
  • Promise.config.setAsyncNotifier created.
  • Promise constructor callback will be invoked with a 3rd "notify" function…which does nothing.
  • Promise.defer.resolve will reject the promise if an Error instance if provided.
  • Promise.some will accept an array or object and resolve with the same type.
  • Promise.all will accept an array or object and resolve with the same type.
  • Promise.any will accept an array or object and resolve with the same type.
  • Promise.settle will accept an array or object and resolve with the same type.
  • Promise.resolve will return a rejected promise if an Error instance is provided.
  • Promise.cast/when will return a rejected promise if an Error instance is provided.
  • Promise.delay will return a rejected promise if an Error instance is provided.

Instance Changes

  • promise.done created.
  • promise.spread created.
  • promise.timeout created.
  • promise.value/getValue created.
  • promise.isResolved created.
  • promise.isRejected created.
  • promise.isSettled created.
  • promise.unwrap created.
  • promise.then will return a rejected promise if an Error instance is returned from a callback.
  • promise.then will invoke the handler registered using Promise.config.setAsyncNotifier.
  • promise.catch/else will return a rejected promise if an Error instance is returned from a callback.
  • promise.catch/else can be passed an array of Error types to conditionally invoke the callback.
  • promise.catch/else will swallow a rejection if no callback is provided.
  • Promise.tap will not reject, even when a rejected promise is returned from the callback.
  • Promise.finally will pass the callback the resolved value or rejection reason.

Assumptions:

  • The wrapped Promise's constructor callback will be invoked synchronously.
Source:
Examples
import asBloodhound from 'bloodhound-promises';

export const BloodhoundPromise = asBloodhound(Promise);
import Q from 'q';
import asBloodhound from 'bloodhound-promises';

export const BloodhoundPromise = asBloodhound(Q.Promise);
import when from 'when';
import asBloodhound from 'bloodhound-promises';

export const BloodhoundPromise = asBloodhound(when.promise);
import * as Bluebird from "bluebird";
import asBloodhound from 'bloodhound-promises';

export const BloodhoundPromise = asBloodhound(Bluebird.Promise);
Parameters:
Name Type Description
PromiseConstructor function

The Promise constructor to wrap.

Returns:

A BloodhoundPromise constructor that uses the wrapped Promise's scheduler to implement advanced functionality.

Type
BloodhoundPromise