Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cancelable deferreds should resolve normally #23

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: 4 additions & 2 deletions cancelable.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
11 changes: 11 additions & 0 deletions test/cancelable.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
});

Expand Down