mercredi 31 août 2016

Resolving multiple promises at once that have dependencies on each other

I am using ember-async button which will show a spinner until the actions promise resolves.



In my case I can't start the child promises until the parent promise has resolved.

This does not work, the spinner will stop as soon as the parent promise resolves.

actions: {
  save(model) {
    cont promise = model.save();

    promise.then(() => {
      const promises = [];
      model.get('subModels').forEach((subModel) => {
        promises.pushObject(subModel.save());
      });

      return Ember.RSVP.all(promises);
    });

    return promise;
  }
}

How do I keep a long running promise running until all dependent promises have finished, taking into account that some of the promises are dependent on others completing?




Aucun commentaire:

Enregistrer un commentaire