简体   繁体   中英

Does Ember.RSVP.all.then take 1 or 2 parameters?

I'm creating a function that sends off a bunch of promises and I want to let the user know what happened when they have all resolved. But, I'm not sure what parameters Ember.RSVP.all.then() should take. Right now I have something like this:

Ember.RSVP.all(promises).then(
  (success) ->
    do stuff...
  (error) ->
    handle errors
)

But, I've also seen a pattern like this:

Ember.RSVP.all(promises).then(
  (values) ->
    do stuff...
).catch(
  (values) ->
    handle errors
)

Any clarification on this would be greatly appreciated. Thanks!

After an unfortunate flame war with an SO Soup Nazi and reading through the source of this undocumented method, I've finally figured out what is going on.

RSVP.all() returns a promise so chaining then onto it takes 2 functions as parameters(referred to as resolve() and reject() ). The confusing part of this method is that resolve() is passed an array of resolved promises where reject() is passed the first promise that is rejected.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM