- From: Andrea Giammarchi <notifications@github.com>
- Date: Mon, 30 Mar 2015 08:34:15 -0700
- To: whatwg/fetch <fetch@noreply.github.com>
- Message-ID: <whatwg/fetch/issues/27/87724683@github.com>
> That's precisely the point I've made many times in this thread, that you don't always need both and that's my point and implementation too. You expose the cancel-ability **only** if you define a method to cancel. Actually my code goes further than that, if you don't internally define a method to cancel and you use `p.cancel()` just for fun, you gonna have an error because I am proposing indeed backward compatibility. The implicit cancellation suits perfectly `fetch` because it doesn't matter what happens in the core, behind the scene, as long as we know the object can be canceled, either via contrller or `.cancel()` we are good. My explicit promise creation is like that because **as a user, I want to be also able to create cancel-able Promises** and there it goes: if core or external APIs provides cancel-able promises, you can cancel them ... otherwise you cannot, as easy as this sound. The `cancel` as `reject` is a Jake idea and since I've said my code would have been simplified in that way, here I come with the example that rejects through cancel: [here it is](https://gist.github.com/WebReflection/0ca8fac8013f76fb4d06) In this case the `.cancel` rejects but then it breaks the whole chain so that this will stop at the first catch, although resolving everything without invoking. ```js new Promise(function ($res, $rej, ifCanceled) { var internal = setTimeout($rej, 1000); ifCanceled(function () { clearTimeout(internal); }); }) .then( function () { console.log('on time'); }, // we'll end up here function () { console.log('error'); } ) .cancel({beacuse:'reason'}) // never executed .then(function (value) { console.log(value); }); ``` If you are careless about errors, this might work ... but ... I honestly prefer [my first idea](https://gist.github.com/WebReflection/a015c9c02ff2482d327e), creating a mark-point in the chain where everything happened before will be ignored but whoever cancel has the ability to react after, eventually providing the resolution. Anyway, we have 2 playgrounds now. --- Reply to this email directly or view it on GitHub: https://github.com/whatwg/fetch/issues/27#issuecomment-87724683
Received on Monday, 30 March 2015 15:34:46 UTC