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

I've forked [then/promise into ignorablePromise](https://github.com/mariusGundersen/ignorablePromise/blob/master/lib/core.js), and made it work the way I believe it should. This includes ignoring up a chain, calling an ignore method in the initial promise, and cancelling down a chain. This proposal uses reference counting and it attempts to cancel/ignore promises that make up the chain, but makes no guarantees. For example:

```js
function greetMe(greeting){
  return new Promise(function(resolve, _, onIgnored){
    var token = setTimeout(() => resolve(greeting), 100);
    onIgnored(() => clearTimeout(token));
  });
}
simple: {
  let a = greetMe('hello');
  a.then(greeting => console.log(greeting));//this never happens
  a.ignore();
}
refCount: {
  let a = greetMe('hello');
  let b = a.then(greeting => console.log(greeting, 'world'));//this never happens
  let c = a.then(greeting => console.log(greeting, 'jake'));//this happens
  b.ignore();
}
double: {
  let a = greetMe('hello');
  let c = a.then(greeting => greetMe('world'));
  setTimeout(() => c.ignore(), 150);//this will ignore the greetMe('world') promise
}
resolved:{
  let a = Promise.resolve("value");
  a.then(r => console.log(r)); //this happens
  a.ignore();
  a.then(r => console.log(r)); //this never happens
}
```

This implementation attempts to cancel the work being done, but makes no guarantees that it will happen. Instead it makes every effort to ignore the result of a promise. When a promise has been ignored then from the outside it looks like a forever pending promise. To clean up, an ignored promise will ignore up the pending chain and it will cancel down the pending chain. A resolved promise that is ignored will not do anything up or down the promise chain; it will only affect promises created from it afterwards. 

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

Received on Sunday, 5 April 2015 20:30:41 UTC