Skip to content

Commit

Permalink
Merge pull request #87 from dwickern/cancel
Browse files Browse the repository at this point in the history
fix upload promise not being cancellable
  • Loading branch information
tim-evans authored Nov 30, 2017
2 parents 17872a5 + d4f06c7 commit b652a45
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
6 changes: 6 additions & 0 deletions addon/system/http-request.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,12 @@ export default function (options = {}) {
}
return aborted.promise;
};
promise.then = function(...args) {
let newPromise = RSVP.Promise.prototype.then.apply(this, args);
newPromise.cancel = promise.cancel;
newPromise.then = promise.then;
return newPromise;
};
request.onabort = bind(this, function () {
this.onabort();
aborted.resolve();
Expand Down
13 changes: 13 additions & 0 deletions tests/unit/system/http-request-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,19 @@ test(`confirm withCredentials: undefined by default`, function (assert) {
assert.equal(this.request.withCredentials, undefined);
});

test('promise is cancellable', function (assert) {
this.subject.open('PUT', 'http://emberjs.com');
let promise = this.subject.send();
assert.ok(typeof promise.cancel === 'function', 'returned promise should have a cancel() method');

let promise2 = promise
.then(function() { })
.catch(function() { })
.finally(function() { });

assert.ok(typeof promise2.cancel === 'function', 'chained promise should have a cancel() method');
});

skip('onprogress', function () {

});
Expand Down

0 comments on commit b652a45

Please sign in to comment.