Re: [fetch] Aborting a fetch (#27)

> In that thread, I suggested that an async function should return an object (ahem, controller) rather than a promise itself.

I am totally with this (if we talking about extending/fixing ```fetch``` itself). I ended up with it [here](https://gist.github.com/NekR/4bb5190e451d164d17b1). Why the hell ```fetch``` should return ```Promise```? Why not ```Fetch``` instance?

So basicly it might look like this:
```javascript
var req = fetch('...'); // new Fetch

// or req.headers
req.response.then(function(response) {
  if (response.headers.get('Content-Type') !== 'application/json') {
    req.abort(); // or cancel
  }

  return response.json();
});

req.addEventListener('abort', function() {
  // blah blah
});

// or for crazy minds Streams-like way
req.closed.then(function() { ... });
```

... but this is about "fixing" ```fetch```. For me, ```fetch``` seems like a library, like ```$.ajax```. It's nice **wrap**. It's nice API what I can implement with XHR and it's hard for me think about implementing XHR via ```fetch```. XHR easily can have ```xhr.responseType = 'stream'``` or ```xhr.mode = 'no-cors'```.

Guys, please, if you really want low-level API them implement it as a low-level API, not a **promised-cool-shine-thing**, that thing can developer every good (or not) web developer, but real low-level API are able to develop only browser vendors.

---
Reply to this email directly or view it on GitHub:
https://github.com/whatwg/fetch/issues/27#issuecomment-86841544

Received on Friday, 27 March 2015 06:30:12 UTC