{"action":"created","issue":{"url":"https://api.github.com/repos/petkaantonov/bluebird/issues/565","labels_url":"https://api.github.com/repos/petkaantonov/bluebird/issues/565/labels{/name}","comments_url":"https://api.github.com/repos/petkaantonov/bluebird/issues/565/comments","events_url":"https://api.github.com/repos/petkaantonov/bluebird/issues/565/events","html_url":"https://github.com/petkaantonov/bluebird/issues/565","id":66368115,"number":565,"title":"Don't use a third \"cancelled\" state","user":{"login":"bergus","id":1146478,"avatar_url":"https://avatars.githubusercontent.com/u/1146478?v=3","gravatar_id":"","url":"https://api.github.com/users/bergus","html_url":"https://github.com/bergus","followers_url":"https://api.github.com/users/bergus/followers","following_url":"https://api.github.com/users/bergus/following{/other_user}","gists_url":"https://api.github.com/users/bergus/gists{/gist_id}","starred_url":"https://api.github.com/users/bergus/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bergus/subscriptions","organizations_url":"https://api.github.com/users/bergus/orgs","repos_url":"https://api.github.com/users/bergus/repos","events_url":"https://api.github.com/users/bergus/events{/privacy}","received_events_url":"https://api.github.com/users/bergus/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/petkaantonov/bluebird/labels/3.0.0","name":"3.0.0","color":"5319e7"}],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":34,"created_at":"2015-04-04T21:03:28Z","updated_at":"2015-04-08T13:46:16Z","closed_at":"2015-04-05T07:40:24Z","body":"(please tag 3.0)\r\n\r\nIt seems that #415 established that there should be no extra \"cancelled\" state. However, the current implementation seems to do just that - it settles the promise, and propagates this downstream, calling only `onCancel` and `finally` handlers but no `onFulfilled` or `onRejected` ones. E.g. in the test case described in #564, where a `then` callback returns a cancelled promise that is subsequently adopted and triggers a downstream `onCancel`.\r\n\r\nFor me, a cancellation should only propagate upstream, where it prevents fulfillment/rejection callbacks from being invoked, stops ongoing tasks and cleans up resources (by triggering `onCancel` and `finally` callbacks).\r\n```\r\nvar p = Promise.delay(50).onCancel(expectCall()).then(expectNoCall(), expectNoCall()).finally(expectCall());\r\nPromise.delay(25).then(() => { p.cancel(); assert(expectations); });\r\n```\r\nThe **cancellation should not propagate downstream**. Instead, rejection with a CancellationError (for those who peek, usually `.cancel()` is called at the end of the chain anyway) seems appropriate here.\r\n```\r\np.then(expectNoCall, expectCall()).onCancel(expectNoCall()); // regardless whether they are directly chained\r\nPromise.delay(50).then(() => p.then(expectNoCall, expectCall()).onCancel(expectNoCall()) ); // or come later\r\nPromise.delay(75).then(() => { assert(expectations); });\r\n```"},"comment":{"url":"https://api.github.com/repos/petkaantonov/bluebird/issues/comments/90921873","html_url":"https://github.com/petkaantonov/bluebird/issues/565#issuecomment-90921873","issue_url":"https://api.github.com/repos/petkaantonov/bluebird/issues/565","id":90921873,"user":{"login":"petkaantonov","id":829734,"avatar_url":"https://avatars.githubusercontent.com/u/829734?v=3","gravatar_id":"","url":"https://api.github.com/users/petkaantonov","html_url":"https://github.com/petkaantonov","followers_url":"https://api.github.com/users/petkaantonov/followers","following_url":"https://api.github.com/users/petkaantonov/following{/other_user}","gists_url":"https://api.github.com/users/petkaantonov/gists{/gist_id}","starred_url":"https://api.github.com/users/petkaantonov/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/petkaantonov/subscriptions","organizations_url":"https://api.github.com/users/petkaantonov/orgs","repos_url":"https://api.github.com/users/petkaantonov/repos","events_url":"https://api.github.com/users/petkaantonov/events{/privacy}","received_events_url":"https://api.github.com/users/petkaantonov/received_events","type":"User","site_admin":false},"created_at":"2015-04-08T13:46:16Z","updated_at":"2015-04-08T13:46:16Z","body":"> If Bluebird uses this in 3.0, I'm looking forward to see how you implement the ref-counting and callback-cancelling efficiently\r\n\r\nWell, I don't :-D. Cancellation is already behind a switch because it takes 3 additional fields on the promise  + new closure needs to be allocated for every `new Promise`. But you only pay for this if you actually use cancellation."}}