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

@benjamingr Thanks for the response.  I'd read https://github.com/kriskowal/gtor before but reading it again is fairly illuminating:

> Promises are **broadcast**.
> 
> The law that no consumer can interfere with another consumer makes it impossible for promises to abort work in progress. A promise represents a result, not the work leading to that result.
> 
> A **task** has mostly the same form and features as a promise, but is unicast by default and can be cancelled. A task can have only one subscriber, but can be explicitly forked to create a new task that depends on the same result. Each subscriber can unsubscribe, and if all subscribers have unsubscribed and no further subscribers can be introduced, a task can abort its work.
> 
> Tasks are **unicast** and therefore cancelable.
>
> See the accompanying sketch of a [task](http://kriskowal.github.io/gtor/docs/task) implementation.

I appreciate the correction, the important distinction then is multicast (like Promise) vs unicast (like Task or Stream).  I was wrong that Task separates .map and .subscribe. The sketch implementation has separate .then (.map.subscribe) and .done (.subscribe) methods, only one of which is allowed to be called, and only once, on a given task.

So, it matters that map and subscribe are conflated for multicast values because multiple consumers can e.g. .then a Promise, leading to interference in the case where cancellation or disinterest is added.  It doesn't matter if *unicast* values have a .then method which does both, because calling it twice on the same Task (instead of calling .fork explicitly) is an error.

You mentioned Bluebird and I think that's a really interesting example.  Bluebird v2 seems to have cancellation semantics, which I think we agree isn't the solution, while v3 has disinterest semantics.  The [documentation](http://bluebirdjs.com/docs/api/cancellation.html) mentions the reference counting technique, which I think is the most viable way to have this work.

It still suffers from interference, though.  What would you expect to happen here?

```javascript
var promise = fetch(url);
promise.then(sub1);
promise.then(sub2);
promise.cancel();
```

> Nope, just because you created another reference to a promise does not mean you've created another promise.

This is likely a nitpick but for the example @appden gave, based on the [Promises/A+ spec](https://promisesaplus.com/#point-40), there will absolutely be a second Promise created if retreiveResult returns a value, will there not?

```javascript
let responsePromise = fetch(url).then(parseResponse);
let resultPromise = responsePromise.then(retrieveResult);
```

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

Received on Saturday, 30 January 2016 18:13:12 UTC