- From: Jake Archibald <notifications@github.com>
- Date: Fri, 27 Mar 2015 08:47:13 -0700
- To: whatwg/fetch <fetch@noreply.github.com>
- Message-ID: <whatwg/fetch/issues/27/86981339@github.com>
@NekR that's already possible with the shipped API ```js fetch(url).then(response => { if (response.headers.get('Content-Type') !== 'application/json') { response.body.cancel(); } }); ``` We can already abort the response, it's the request we can't abort. The only case this is a problem is when the request is particularly large, say you're uploading a large file. It's trivial to do what you're suggesting whilst still returning a promise. `fetch()` could return a subclass that has an abort method that terminates the request or in-progress response stream. The [`@@species`](https://people.mozilla.org/~jorendorff/es6-draft.html#sec-get-promise-@@species) of that subclass would be `Promise`, so calls to `.then` would return a regular promise, and there's no chain to worry about. The question is whether there's a benefit in the `@@species` also being abortable. ```js // If @@species is a regular promise: var fetchPromise = fetch(url); var jsonPromise = fetchPromise.then(r => r.json()); // To abort the request & response: fetchPromise.abort(); // If @@species is abortable: var jsonPromise = fetch(url).then(r => r.json()); // To abort the request & response: jsonPromise.abort(); ``` --- Reply to this email directly or view it on GitHub: https://github.com/whatwg/fetch/issues/27#issuecomment-86981339
Received on Friday, 27 March 2015 15:47:35 UTC