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

'k. Say we have a careless or cancellation-ignorant library author who writes:
```javascript
function myTransform(yourPromise) {
  return yourPromise
    .then(value => transform(value))
    .then(value => transform2(value));
```

If we had `myTransform(fetch(...)).cancel()`, that intermediate, uncancelled `.then()` will prevent the fetch from ever aborting, right? (This would be fixed if GC contributed to cancellation, but there's a lot of resistance to making GC visible.)

On the other hand, in a `CancellationToken` approach like https://msdn.microsoft.com/en-us/library/dd997364%28v=vs.110%29.aspx, we'd write:

```javascript
var cancellationSource = new CancellationTokenSource();
var result = myTransform(fetch(..., cancellationSource.token));
cancellationSource.cancel();
```
And the fetch would wind up rejecting despite the intermediate function's obliviousness to cancellation.

The "revealing constructor pattern" is bad for cancellation tokens because it requires special infrastructure to be able to cancel two fetches from one point. On the other side, cancellation tokens require special infrastructure to be able to use one fetch for multiple different purposes.

Either of Anne's solutions can, of course, be wrapped into something compatible with either `CancellablePromise` or `CancellationToken` if the goal here is to get something quickly instead of waiting for the long-term plan to emerge.

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

Received on Thursday, 26 March 2015 18:06:37 UTC