小编Val*_*ala的帖子

拒绝/解决身体外的承诺

我需要拒绝来自其身体外的承诺,以处理想要取消操作的用户的情况.

在这里,我需要通过在每个排队的上传中调用#start来同时启动多个上传.管理上传队列的类然后存储所有承诺和用于Ember.RSVP.all处理所有承诺已解决或拒绝的承诺.这很好用.

现在,我想取消上传

App.Upload = Ember.Object.extend({
  start: function() {
    var self = this;

    return new Ember.RSVP.Promise(function(resolve, reject) {
      self.startUpload() // Async upload with jQuery
        .then(
          function(resp) { resolve(resp) },
          function(error) { reject(error) }
        );
    });
  },

  cancel: function() {
    this.get('currentUpload').cancel() // Works, and cancels the upload
    // Would like to reject the promise here
  },

  startUpload: function() {
    return this.set('currentUpload', /* some jqXHR that i build to upload */)
  }
});
Run Code Online (Sandbox Code Playgroud)

我已经想到了很多方法来处理它,但我没有找到任何方法myPromise.reject(reason).

所以我做的是将reject函数存储在Upload …

promise cancellation ember.js

6
推荐指数
1
解决办法
2503
查看次数

标签 统计

cancellation ×1

ember.js ×1

promise ×1