Q.allSettled
domenic opened this issue · 2 comments
Q.allResolved
is misnamed (due to our new meaning of "resolved" over in promises-aplus/constructor-spec#18) and relies on the clunky synchronous inspection API. I propose Q.allSettled
, which always fulfills with an array of the snapshot objects from #256.
Usage example:
return Q.allSettled([rejectedWith5, fulfilledWith10]).spread(function (one, two) {
assert(one.state === "rejected");
assert(one.reason === 5);
assert(two.state === "fulfilled");
assert(two.value === 10);
});
I am proposing something similar for when.js over in cujojs/when#119 (comment) which is getting somewhat-positive reception.
Trivial question w.r.t naming: if the deferred.reject() has state "rejected", then shouldn't deferred.resolve() have state "resolved" and not "fulfilled"? (assuming I am reading this all correctly).
@ravi There’s a nuance there.
deferred.reject(reason)
is really a synonym for deferred.resolve(Q.reject(reason))
. The argument of resolve
can be a promise in any state—or—a value
which gets implicitly boxed as a fulfilled promise for that value (Q(value)
).
So, resolve
can actually transition a deferred to any state, pending
(through resolving to a deferred promise), rejected
(through resolving to a rejected promise), or fulfilled
(through resolving to a fulfilled promise, or simply to a value).