Q.allSettled #257

Closed
domenic opened this Issue Apr 5, 2013 · 2 comments

Projects

None yet

3 participants

@domenic
Collaborator

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.

@domenic domenic closed this in 1eefd58 Jun 4, 2013
@ravi

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).

@kriskowal
Owner

@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).

@mmun mmun referenced this issue in tildeio/rsvp.js Sep 17, 2013
Merged

Add allSettled to RSVP #113

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment