{"action":"created","issue":{"url":"https://api.github.com/repos/domenic/cancelable-promise/issues/1","labels_url":"https://api.github.com/repos/domenic/cancelable-promise/issues/1/labels{/name}","comments_url":"https://api.github.com/repos/domenic/cancelable-promise/issues/1/comments","events_url":"https://api.github.com/repos/domenic/cancelable-promise/issues/1/events","html_url":"https://github.com/domenic/cancelable-promise/pull/1","id":68713109,"number":1,"title":"Adopt the sate of promises without taking a reference","user":{"login":"ForbesLindesay","id":1260646,"avatar_url":"https://avatars.githubusercontent.com/u/1260646?v=3","gravatar_id":"","url":"https://api.github.com/users/ForbesLindesay","html_url":"https://github.com/ForbesLindesay","followers_url":"https://api.github.com/users/ForbesLindesay/followers","following_url":"https://api.github.com/users/ForbesLindesay/following{/other_user}","gists_url":"https://api.github.com/users/ForbesLindesay/gists{/gist_id}","starred_url":"https://api.github.com/users/ForbesLindesay/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ForbesLindesay/subscriptions","organizations_url":"https://api.github.com/users/ForbesLindesay/orgs","repos_url":"https://api.github.com/users/ForbesLindesay/repos","events_url":"https://api.github.com/users/ForbesLindesay/events{/privacy}","received_events_url":"https://api.github.com/users/ForbesLindesay/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":4,"created_at":"2015-04-15T15:28:01Z","updated_at":"2015-04-18T02:29:22Z","closed_at":null,"pull_request":{"url":"https://api.github.com/repos/domenic/cancelable-promise/pulls/1","html_url":"https://github.com/domenic/cancelable-promise/pull/1","diff_url":"https://github.com/domenic/cancelable-promise/pull/1.diff","patch_url":"https://github.com/domenic/cancelable-promise/pull/1.patch"},"body":"See promises-aplus/promises-spec#179\r\n\r\nThe basic idea is to implement a new state \"adopted\", which reverses the references.  Incidentally, it's still possible to get a memory leak with something like:\r\n\r\n```js\r\nfunction run() {\r\n    return  new Promise(function(resolve) {\r\n        setImmediate(resolve);\r\n    }).then(run);\r\n}\r\n\r\n// here this `x` will keep a reference to the entire gradually expanding chain of promises\r\nvar x = run();\r\n```\r\n\r\nbut this fixes the leak in the case of:\r\n\r\n```js\r\nfunction run() {\r\n    return  new Promise(function(resolve) {\r\n        setImmediate(resolve);\r\n    }).then(run);\r\n}\r\nrun().then(function () {\r\n  console.log('this never actually gets called');\r\n});\r\n```\r\n\r\nI'm not sure if it's possible to fix both scenarios."},"comment":{"url":"https://api.github.com/repos/domenic/cancelable-promise/issues/comments/94118025","html_url":"https://github.com/domenic/cancelable-promise/pull/1#issuecomment-94118025","issue_url":"https://api.github.com/repos/domenic/cancelable-promise/issues/1","id":94118025,"user":{"login":"domenic","id":617481,"avatar_url":"https://avatars.githubusercontent.com/u/617481?v=3","gravatar_id":"","url":"https://api.github.com/users/domenic","html_url":"https://github.com/domenic","followers_url":"https://api.github.com/users/domenic/followers","following_url":"https://api.github.com/users/domenic/following{/other_user}","gists_url":"https://api.github.com/users/domenic/gists{/gist_id}","starred_url":"https://api.github.com/users/domenic/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/domenic/subscriptions","organizations_url":"https://api.github.com/users/domenic/orgs","repos_url":"https://api.github.com/users/domenic/repos","events_url":"https://api.github.com/users/domenic/events{/privacy}","received_events_url":"https://api.github.com/users/domenic/received_events","type":"User","site_admin":false},"created_at":"2015-04-18T02:29:22Z","updated_at":"2015-04-18T02:29:22Z","body":"Maybe instead of directly transferring the [[FulfillReactions]] and [[RejectReactions]] (both in AdoptPromise and in PerformPromiseThen) we can just call `adoptee.then(...)` appropriately. Will have to try it."}}