Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

feat($q): add Promise.progress shorthand for notifyCallbacks #4501

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions src/ng/q.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,8 @@
*
* - `catch(errorCallback)` – shorthand for `promise.then(null, errorCallback)`
*
* - `progress(notifyCallback)` – shorthand for `promise.then(null, null, notifyCallback)`
*
* - `finally(callback)` – allows you to observe either the fulfillment or rejection of a promise,
* but to do so without modifying the final value. This is useful to release resources or do some
* clean-up that needs to be done whether the promise was rejected or resolved. See the [full
Expand Down Expand Up @@ -288,6 +290,10 @@ function qFactory(nextTick, exceptionHandler) {
return this.then(null, callback);
},

progress: function(callback) {
return this.then(null, null, callback);
},

"finally": function(callback) {

function makePromise(value, resolved) {
Expand Down
13 changes: 13 additions & 0 deletions test/ng/qSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -524,6 +524,10 @@ describe('q', function() {
expect(typeof promise['finally']).toBe('function');
});

it('should have a progress method', function () {
expect(typeof promise.progress).toBe('function');
});


describe('then', function() {
it('should allow registration of a success callback without an errback or progressback ' +
Expand Down Expand Up @@ -923,6 +927,15 @@ describe('q', function() {
expect(logStr()).toBe('error1(foo)->reject(foo); error2(foo)->reject(foo)');
});
});

describe('progress', function () {
it('should be a shorthand for defining promise progress handlers', function() {
promise.progress(progress(1)).then(null, null, progress(2));
deferred.notify('foo');
mockNextTick.flush();
expect(logStr()).toBe('progress1(foo)->foo; progress2(foo)->foo');
})
});
});
});

Expand Down