diff --git a/cancelable.js b/cancelable.js index 48f3b118..92afd8bc 100644 --- a/cancelable.js +++ b/cancelable.js @@ -41,10 +41,12 @@ define(function() { // Replace deferred's promise with a promise that will always call canceler() first, *if* // deferred is canceled. Can now safely give out deferred.promise - deferred.promise = deferred.then(null, + deferred.promise = deferred.then( + function(v) { return v; }, function cancelHandler(e) { throw e === canceled ? canceler(deferred) : e; - }); + } + ); // Replace deferred.then to allow it to be called safely and observe the cancellation deferred.then = deferred.promise.then; diff --git a/test/cancelable.js b/test/cancelable.js index 9afe9cfc..48bc1567 100644 --- a/test/cancelable.js +++ b/test/cancelable.js @@ -39,6 +39,17 @@ buster.testCase('when/cancelable', { } ); + }, + + 'should invoke the callback with the resolved value': function() { + var c = cancelable(when.defer(), function() {}); + c.then( + function(v) { + assert.same(1, v); + done(); + } + ); + c.resolve(1); } });