Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Q.allSettled #257

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

Q.allSettled #257

domenic opened this issue Apr 5, 2013 · 2 comments

Comments

@domenic
Copy link
Collaborator

domenic commented Apr 5, 2013

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.

@ravi
Copy link

ravi commented Jun 14, 2013

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

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

No branches or pull requests

3 participants