For the following methods please keep in mind these assumptions on the
input
argument:
input
is an array each item is considered for the race. If it is an
object, each own value is considered.input
is a thenable, the race result may be an object with a then
function (but not the same thenable). Or if a thenable is an item in an input
array, or an own value if an input object, it's returned as-is.Like Promise.all()
, but the returned promise won't be rejected until it's
no longer possible to get a number of fulfillment values equivalent to
winsRequired
. The returned promise is fulfilled once the total number of
fulfillment values is equivalent to winsRequired
.
The returned promise is fulfilled with a mapping of fulfillment values for
the input, according to its type, and similarly rejected with
a mapping of rejection reasons. Note that the value/reason may be a sparse
array, or an object with fewer keys than input
.
The wrapper function will return a new promise. If func
throws, the
returned promise will be rejected with that error as the rejection reason. If
func
invokes its callback with a truey error argument, the returned promise
will be rejected with that error as the rejection reason.
If func
invokes its callback with a falsey error argument, and no other
arguments, the returned promise will be fulfilled with undefined
.
If func
invokes its callback with a falsey error argument, and one other
argument, the returned promise will be fulfilled with the second argument
value.
If func
invokes its callback with a falsey error argument, and multiple
arguments, the returned promise will be fulfilled with an array of argument
values (excluding the first error argument).
Subsequent invocations of the callback are ignored.
func
is applied to the thisArg
of the wrapped function invocation. It'll
be invoked with the other arguments that are passed. These arguments are used
as-is.
The wrapper will provide a callback function as the last argument, based on
func
s arity. If func
does not actually declare a callback argument, but
uses arguments
array to find the last argument, call Promise.denodeify()
with callbackNotDeclared
set to true
.
then
method according to Promises/A+.
Can be called as a free function, without the promise instance as a
thisArg
. For example:
var then = promise.then;
then(function(value) {
console.log('value:', value);
});
Behaves the same as:
promise.then(function(value) {
console.log('value:', value);
});
Please note that only those methods documented as free functions can be called as such.
isFulfilled
and isRejected
are false
, the promise
is pending.isFulfilled
is true
, then isRejected
will be false
, and the
promise is fulfilled. The fulfillment value is available via the value
property, which does not exist when the promise is pending or rejected.isRejected
is true
, then isFulfilled
will be false
, and the
promise is rejected. The rejection reason is available via the reason
property, which does not exist when the promise is pending or fulfilled.Like then
, can be called as a free function.
When cancelled, the pending promise is rejected with a
CancellationError
. If the promise is in the
process of adopting the state of another promise, the cancellation is
propagated by invoking the cancel
method on that promise. If instead the
promise is assimilating a thenable, it merely gives up on the assimilation,
but does not attempt to invoke a cancel
method on that thenable.
Like then
, can be called as a free function.
var forked = promise.fork();
promise.then(null, function(reason) {
console.log("original promise rejected:", reason.name);
});
forked.then(null, function(reason) {
console.log("returned promise rejected:", reason.name);
});
forked.cancel(); // Logs: returned promise rejected: cancel
var uncancellable = promise.uncancellable();
promise.then(null, function(reason) {
console.log("original promise rejected:", reason.name);
});
uncancellable.then(null, function(reason) {
console.log("returned promise rejected:", reason.name);
});
uncancellable.cancel(); // Logs nothing
var promise = Promise.from([0, 1, 2, 3, 4]);
var series = promise.to(Series);
And then we can use the helper methods from Series
to filter the array:
var odd = series.filter(function(n) {
return n % 2;
});
odd.then(console.log); // Logs: [ 1, 3 ]
Assumes constructor
has a from
method, like
Promise.from()
.
label
is expected to be a string. meta
can be any value.
var fulfilled = Promise.from(42);
var rejected = fulfilled.yieldReason(
new Error("We apologise for the inconvenience"));
rejected.then(null, function(reason) {
console.log(reason.message);
}); // Logs: We apologise for the inconvenience
Invokes onFulfilledOrRejected
when the promise leaves the pending state,
but without any arguments. Returns a promise that adopts the original state,
unless onFulfilledOrRejected
throws, or returns a rejected promise, in
which case the returned promise is rejected with that exception or reason.
Adds onFulfilledSideEffect
and onRejectedSideEffect
as callbacks, like
if then
was used, but unless those functions throw, returns a promise that
adopts the original state. If the callbacks do throw, the returned promise is
rejected with that exception.
The returned promise will be rejected if the original promise is not
fulfilled with an array; rejects; or if not all fulfillment values can be
collected. See Promise.all
for more detail on the
semantics.
other
is a promise, and the current promise is cancelled, so
will other
.other
is an array, each item that is a promise is cancelled when the
current promise is cancelled.other
is an object, each own value that is a promise is cancelled
when the current promise is cancelled.
Promise
Promise/A+ compatible promise constructor.