[fetch] Aborting a fetch (#27)

## Goal

Provide developers with a method to abort something initiated with `fetch()` in a way that is not overly complicated.

## Previous discussion

* https://github.com/whatwg/fetch/issues/20
* https://github.com/slightlyoff/ServiceWorker/issues/592
* https://github.com/slightlyoff/ServiceWorker/issues/625

## Viable solutions

We 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.

### A promise-subclass

In 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.

    var f = fetch(url)
    f.terminate()

Note: 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.

### A controller

The 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:

    var c = new FetchController
    fetch(url, {controller: c})
    c.abort()

Revealing constructor pattern:

    fetch(url, controller(c => c.abort()))

## Open issues

* 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?
* What is the effect on the stream? I suspect the Streams Standard is already conclusive on this.
* What syntax of the above two-three solutions do we favor?

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

Received on Thursday, 26 March 2015 09:09:08 UTC