{"action":"created","issue":{"url":"https://api.github.com/repos/petkaantonov/bluebird/issues/537","labels_url":"https://api.github.com/repos/petkaantonov/bluebird/issues/537/labels{/name}","comments_url":"https://api.github.com/repos/petkaantonov/bluebird/issues/537/comments","events_url":"https://api.github.com/repos/petkaantonov/bluebird/issues/537/events","html_url":"https://github.com/petkaantonov/bluebird/issues/537","id":63245090,"number":537,"title":"Promise.using doesn't work with cancellation as expected.","user":{"login":"Page-","id":360115,"avatar_url":"https://avatars.githubusercontent.com/u/360115?v=3","gravatar_id":"","url":"https://api.github.com/users/Page-","html_url":"https://github.com/Page-","followers_url":"https://api.github.com/users/Page-/followers","following_url":"https://api.github.com/users/Page-/following{/other_user}","gists_url":"https://api.github.com/users/Page-/gists{/gist_id}","starred_url":"https://api.github.com/users/Page-/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Page-/subscriptions","organizations_url":"https://api.github.com/users/Page-/orgs","repos_url":"https://api.github.com/users/Page-/repos","events_url":"https://api.github.com/users/Page-/events{/privacy}","received_events_url":"https://api.github.com/users/Page-/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":1,"created_at":"2015-03-20T15:10:44Z","updated_at":"2015-03-20T15:40:57Z","closed_at":"2015-03-20T15:40:57Z","body":"```javascript\r\nvar Promise = require('bluebird'),\r\n\tcreateDisposer = function() {\r\n\t\tPromise.resolve().disposer(function() {\r\n\t\t\tconsole.log('disposer called')\r\n\t\t});\r\n\t};\r\n\r\nconsole.log('using');\r\nvar p = Promise.resolve().cancellable().then(function() {\r\n\treturn Promise.using(createDisposer(), function() {\r\n\t\tconsole.log('1');\r\n\t\treturn Promise.try(function() {\r\n\t\t\tconsole.log('2');\r\n\t\t})\r\n\t\t.cancellable()\r\n\t\t.delay(2000)\r\n\t\t.then(function() {\r\n\t\t\tconsole.log('3');\r\n\t\t})\r\n\t\t.catch(Promise.CancellationError, function(e) {\r\n\t\t\tconsole.log('cancelled 1', e);\r\n\t\t\tthrow e;\r\n\t\t})\r\n\t\t.then(function() {\r\n\t\t\tconsole.log('4');\r\n\t\t})\r\n\t})\r\n\t.cancellable()\r\n\t.then(function() {\r\n\t\tconsole.log('5');\r\n\t})\r\n\t.catch(Promise.CancellationError, function(e) {\r\n\t\tconsole.log('cancelled 2', e);\r\n\t\tthrow e;\r\n\t});\r\n})\r\n.then(function() {\r\n\tconsole.log('6');\r\n})\r\n.catch(Promise.CancellationError, function(e) {\r\n\tconsole.log('cancelled 3', e);\r\n})\r\np.cancel();\r\n\r\nPromise.delay(5000).then(function() {\r\n\tconsole.log('try');\r\n\tvar p = Promise.resolve().cancellable().then(function() {\r\n\t\treturn Promise.try(function() {\r\n\t\t\tconsole.log('1');\r\n\t\t\treturn Promise.try(function() {\r\n\t\t\t\tconsole.log('2');\r\n\t\t\t})\r\n\t\t\t.cancellable()\r\n\t\t\t.delay(5000)\r\n\t\t\t.then(function() {\r\n\t\t\t\tconsole.log('3');\r\n\t\t\t})\r\n\t\t\t.catch(Promise.CancellationError, function(e) {\r\n\t\t\t\tconsole.log('cancelled 1', e);\r\n\t\t\t\tthrow e;\r\n\t\t\t})\r\n\t\t\t.then(function() {\r\n\t\t\t\tconsole.log('4');\r\n\t\t\t})\r\n\t\t})\r\n\t\t.cancellable()\r\n\t\t.then(function() {\r\n\t\t\tconsole.log('5');\r\n\t\t})\r\n\t\t.catch(Promise.CancellationError, function(e) {\r\n\t\t\tconsole.log('cancelled 2', e);\r\n\t\t\tthrow e;\r\n\t\t});\r\n\t})\r\n\t.then(function() {\r\n\t\tconsole.log('6');\r\n\t})\r\n\t.catch(Promise.CancellationError, function(e) {\r\n\t\tconsole.log('cancelled 3', e);\r\n\t})\r\n\tp.cancel();\r\n});\r\n```\r\nresults in\r\n```\r\nusing\r\n1\r\n2\r\ncancelled 2 [CancellationError: cancellation error]\r\ncancelled 3 [CancellationError: cancellation error]\r\n3\r\n4\r\ntry\r\n1\r\n2\r\ncancelled 1 [CancellationError: cancellation error]\r\ncancelled 2 [CancellationError: cancellation error]\r\ncancelled 3 [CancellationError: cancellation error]\r\n```\r\nWhereas I would expect:\r\n```\r\nusing\r\n1\r\n2\r\ncancelled 2 [CancellationError: cancellation error]\r\ncancelled 3 [CancellationError: cancellation error]\r\ntry\r\n1\r\n2\r\ncancelled 1 [CancellationError: cancellation error]\r\ncancelled 2 [CancellationError: cancellation error]\r\ncancelled 3 [CancellationError: cancellation error]\r\n```\r\nwith the promise returned within the `Promise.using` function being correctly cancelled."},"comment":{"url":"https://api.github.com/repos/petkaantonov/bluebird/issues/comments/84051835","html_url":"https://github.com/petkaantonov/bluebird/issues/537#issuecomment-84051835","issue_url":"https://api.github.com/repos/petkaantonov/bluebird/issues/537","id":84051835,"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-03-20T15:40:57Z","updated_at":"2015-03-20T15:40:57Z","body":"cancellation in 2.x is horribly broken by design and wontfix and cannot be made to work with all bluebird features consistently. Cancellation has been redone for 3.0"}}