- From: Andrea Giammarchi <notifications@github.com>
- Date: Thu, 15 Dec 2016 16:18:30 -0800
- To: whatwg/fetch <fetch@noreply.github.com>
- Cc: Subscribed <subscribed@noreply.github.com>
Received on Friday, 16 December 2016 00:19:03 UTC
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