Wraps a Promise implementation to enable the following behaviors:
Static Changes
Promise.timeoutcreated.Promise.unwrapcreated.Promise.apply/fapplycreated.Promise.call/fcall/try/attemptcreated.Promise.config.setErrorHandlercreated.Promise.config.setAsyncNotifiercreated.- Promise constructor callback will be invoked with a 3rd "notify" function…which does nothing.
Promise.defer.resolvewill reject the promise if an Error instance if provided.Promise.somewill accept an array or object and resolve with the same type.Promise.allwill accept an array or object and resolve with the same type.Promise.anywill accept an array or object and resolve with the same type.Promise.settlewill accept an array or object and resolve with the same type.Promise.resolvewill return a rejected promise if an Error instance is provided.Promise.cast/whenwill return a rejected promise if an Error instance is provided.Promise.delaywill return a rejected promise if an Error instance is provided.
Instance Changes
promise.donecreated.promise.spreadcreated.promise.timeoutcreated.promise.value/getValuecreated.promise.isResolvedcreated.promise.isRejectedcreated.promise.isSettledcreated.promise.unwrapcreated.promise.thenwill return a rejected promise if an Error instance is returned from a callback.promise.thenwill invoke the handler registered usingPromise.config.setAsyncNotifier.promise.catch/elsewill return a rejected promise if an Error instance is returned from a callback.promise.catch/elsecan be passed an array of Error types to conditionally invoke the callback.promise.catch/elsewill swallow a rejection if no callback is provided.Promise.tapwill not reject, even when a rejected promise is returned from the callback.Promise.finallywill pass the callback the resolved value or rejection reason.
Assumptions:
- The wrapped Promise's constructor callback will be invoked synchronously.
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