Skip to content

Commit

Permalink
Simplify nend
Browse files Browse the repository at this point in the history
Do not return a promise if a callback is given.

Spec no longer depends on returned promise.
  • Loading branch information
kriskowal committed Oct 11, 2012
1 parent 7d86d9f commit a7596e0
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 8 deletions.
4 changes: 0 additions & 4 deletions q.js
Original file line number Diff line number Diff line change
Expand Up @@ -1578,19 +1578,15 @@ function ninvoke(object, name /*, ...args*/) {
exports.nend = nend;
function nend(promise, nodeback) {
if (nodeback) {
var deferred = defer();
promise.then(function (value) {
nextTick(function () {
deferred.resolve();
nodeback(null, value);
});
}, function (error) {
nextTick(function () {
deferred.resolve();
nodeback(error);
});
});
return deferred.promise;
} else {
return promise;
}
Expand Down
14 changes: 10 additions & 4 deletions spec/q-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -1415,16 +1415,22 @@ describe("node support", function () {

it("calls back with a resolution", function () {
var spy = jasmine.createSpy();
return Q.resolve(10).nend(spy)
.then(function () {
Q.resolve(10).nend(spy);
waitsFor(function () {
return spy.argsForCall.length;
});
runs(function () {
expect(spy.argsForCall).toEqual([[null, 10]]);
});
});

it("calls back with an error", function () {
var spy = jasmine.createSpy();
return Q.reject(10).nend(spy)
.then(function () {
Q.reject(10).nend(spy);
waitsFor(function () {
return spy.argsForCall.length;
});
runs(function () {
expect(spy.argsForCall).toEqual([[10]]);
});
});
Expand Down

0 comments on commit a7596e0

Please sign in to comment.