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

@martinthomson 

> What is wrong with adding a simpler hook, solely for fetch use?

If there's no agreement on chainable cancellation, we could go with a promise subclass with an `.abort` that rejects the fetch if it's in progress & terminates the stream. This promise would have a `@@species` of `Promise` so there's no cancellation chaining.

Because this terminates the stream, it may be impossible for the reader (eg `.text()`) to know something went wrong, and may resolve with partial content - basically the same that would happen if the connection is abruptly terminated (see my research on this https://github.com/slightlyoff/ServiceWorker/issues/362#issuecomment-49011736). This isn't an issue with the CancellablePromise, as the explict cancellation can be captured.

With cancellation in the chain, it means that:

```js
function higherLevelFetch(url) {
  return fetch(url).then(transformSomeWay).catch(recoverSomeWay);
}
```

...produces an abortable value automatically. We'd lose that if `.then` returned a standard promise.

You also lose the "all children cancelled so cancel parent" behaviour which I think works well for multiple listeners to the same fetch, but maybe if we ever get such a thing fetch could adopt it.

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

Received on Friday, 27 March 2015 18:18:33 UTC