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

I hope we would've kept this as simple as possible, like in 20 lines of logic fix, and eventually iterate later on:
```js
// Native chainability fix
(p => {
  const patch = (orig) => function () {
    const p = orig.apply(this, arguments);
    if (this.hasOwnProperty('cancel')) {
      p.cancel = this.cancel;
    }
    return p;
  };
  p.then = patch(p.then);
  p.catch = patch(p.catch);
})(Promise.prototype);

// Cancelable Promise fix
Promise = (P => function Promise(f) {
  let cancel, p = new P((res, rej) => {
    cancel = (why) => rej({message: why});
    f(res, rej);
  });
  p.cancel = cancel;
  return p;
})(Promise);
```

Above snippet would've made  this possible, without exposing `resolve` or `reject` logic .

```js
var p = new Promise((res, rej) => { setTimeout(res, 1000, 25); });

// later on ...
p.cancel('because');
```

I'd like to thanks the @-unnamable-one for the effort, the patience, and the competence he put, even if he'll never read this message: thank you, it's a pity developers are often and paradoxically incapable of opening their mind, instead of closing themselves in small rooms full of dogmas.

 

-- 
You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub:
https://github.com/whatwg/fetch/issues/27#issuecomment-267483591

Received on Friday, 16 December 2016 00:19:03 UTC