Skip to content
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
32 changes: 32 additions & 0 deletions test/promise-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -660,6 +660,38 @@ define('when/promise-test', function (require) {
}
},

'both': {
'should return a promise': function () {
assert.isFunction(defer().promise.both().then);
},

'should register callback as callback': function (done) {
var d = when.defer();

d.promise.both(
function(err, val) {
assert.equals(val, 1);
done();
}
);

d.resolve(1);
},

'should register callback as errback': function (done) {
var d = when.defer();

d.promise.both(
function(err) {
assert.equals(err, 1);
done();
}
);

d.reject(1);
}
},

'yield': {
'should return a promise': function() {
assert.isFunction(defer().promise.yield().then);
Expand Down
15 changes: 15 additions & 0 deletions when.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,21 @@ define(function () {
}
},

/**
* Calls combinedCallback with (reason, value) on either fulfillment or
* rejection.
* @param {function} combinedCallback handler to be called on either
* fulfillment or rejection.
* @return {Promise}
*/
both: function (combinedCallback) {
return this.then(success, combinedCallback);

function success(value) {
return combinedCallback(null, value);
}
},

/**
* Shortcut for .then(function() { return value; })
* @param {*} value
Expand Down