{"action":"created","issue":{"url":"https://api.github.com/repos/whatwg/fetch/issues/27","repository_url":"https://api.github.com/repos/whatwg/fetch","labels_url":"https://api.github.com/repos/whatwg/fetch/issues/27/labels{/name}","comments_url":"https://api.github.com/repos/whatwg/fetch/issues/27/comments","events_url":"https://api.github.com/repos/whatwg/fetch/issues/27/events","html_url":"https://github.com/whatwg/fetch/issues/27","id":64476705,"number":27,"title":"Aborting a fetch","user":{"login":"annevk","id":1544111,"avatar_url":"https://avatars.githubusercontent.com/u/1544111?v=3","gravatar_id":"","url":"https://api.github.com/users/annevk","html_url":"https://github.com/annevk","followers_url":"https://api.github.com/users/annevk/followers","following_url":"https://api.github.com/users/annevk/following{/other_user}","gists_url":"https://api.github.com/users/annevk/gists{/gist_id}","starred_url":"https://api.github.com/users/annevk/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/annevk/subscriptions","organizations_url":"https://api.github.com/users/annevk/orgs","repos_url":"https://api.github.com/users/annevk/repos","events_url":"https://api.github.com/users/annevk/events{/privacy}","received_events_url":"https://api.github.com/users/annevk/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/whatwg/fetch/labels/addition","name":"addition","color":"fad8c7"}],"state":"open","locked":false,"assignee":{"login":"jakearchibald","id":93594,"avatar_url":"https://avatars.githubusercontent.com/u/93594?v=3","gravatar_id":"","url":"https://api.github.com/users/jakearchibald","html_url":"https://github.com/jakearchibald","followers_url":"https://api.github.com/users/jakearchibald/followers","following_url":"https://api.github.com/users/jakearchibald/following{/other_user}","gists_url":"https://api.github.com/users/jakearchibald/gists{/gist_id}","starred_url":"https://api.github.com/users/jakearchibald/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jakearchibald/subscriptions","organizations_url":"https://api.github.com/users/jakearchibald/orgs","repos_url":"https://api.github.com/users/jakearchibald/repos","events_url":"https://api.github.com/users/jakearchibald/events{/privacy}","received_events_url":"https://api.github.com/users/jakearchibald/received_events","type":"User","site_admin":false},"milestone":null,"comments":270,"created_at":"2015-03-26T09:08:23Z","updated_at":"2016-02-02T16:24:19Z","closed_at":null,"body":"## Goal\r\n\r\nProvide developers with a method to abort something initiated with `fetch()` in a way that is not overly complicated.\r\n\r\n## Previous discussion\r\n\r\n* https://github.com/whatwg/fetch/issues/20\r\n* https://github.com/slightlyoff/ServiceWorker/issues/592\r\n* https://github.com/slightlyoff/ServiceWorker/issues/625\r\n* https://github.com/whatwg/streams/issues/297\r\n\r\n## Viable solutions\r\n\r\nWe have two contenders. Either `fetch()` returns an object that is more than a promise going forward or `fetch()` is passed something, either an object or a callback that gets handed an object.\r\n\r\n### A promise-subclass\r\n\r\nIn order to not clash with cancelable promises (if they ever materialize) we should pick a somewhat unique method name for abortion. I think `terminate()` would fit that bill.\r\n\r\n    var f = fetch(url)\r\n    f.terminate()\r\n\r\nNote: the Twitter-sphere seemed somewhat confused about the capabilities of this method. It would most certainly terminate any ongoing stream activity as well. It's not limited to the \"lifetime\" of the promise.\r\n\r\n### A controller\r\n\r\nThe limited discussion on es-discuss https://esdiscuss.org/topic/cancelable-promises seemed to favor a controller. There are two flavors that keep coming back. Upfront construction:\r\n\r\n    var c = new FetchController\r\n    fetch(url, {controller: c})\r\n    c.abort()\r\n\r\nRevealing constructor pattern:\r\n\r\n    fetch(url, {controller: c => c.abort()})\r\n\r\n## Open issues\r\n\r\n* What is the effect on the promise? Both forever-pending and explicit rejection have reasonable arguments. We could offer the choice to the developer, but what should be the default?\r\n* What is the effect on the stream? I suspect the Streams Standard is already conclusive on this.\r\n* What syntax of the above two-three solutions do we favor?"},"comment":{"url":"https://api.github.com/repos/whatwg/fetch/issues/comments/178670128","html_url":"https://github.com/whatwg/fetch/issues/27#issuecomment-178670128","issue_url":"https://api.github.com/repos/whatwg/fetch/issues/27","id":178670128,"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":"2016-02-02T16:24:19Z","updated_at":"2016-02-02T16:24:19Z","body":"Those .then() and catches() will not be called, but whether the actual operation will be aborted depends (as it should) on the *owner* of the promise. `p` is just the client here."}}