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

cancel actually cancels up to any promise that hasn't finished yet.

The whole point/ease of Promises is the `.then` chain/simplicity so the moment you cancel you want to be sure nothing happening before will reach your promise.

Cancel in my example is the "reset" point and from then on you can use `.then` if you want but just as already resolved Promise.

The main misunderstanding I see in your code is that you used `ifCanceled` as if it's an `onCanceled` or an `onRejected` but actually the cancelability should be provided as callback.

Basically that does **not** work as resolve and reject, that is an optional way to provide cancelability via a function that is responsible to cancel. You are not clearing the setTimeout in there so you provided a callback that does nothing.

Basically you created a cancelable Promise that won't cancel a thing, hence my design that requires you actually do cancel for real because once you've canceled, the Promise is canceled: meaning it cannot possibly be resolved or rejected, it's **done**, and resolved to avoid the forever pending problem.

It's like invoking `reject` after you have invoked `resolve`, that will **not** make your promise rejected.
Accordingly, if you canceled, you canceled.

>From the internal Promise world, it's up to you to provide a way to be canceled externally, but you actually delegate the outer world to invoke the `.cancel()` method.

You might also want to cancel from the internal world, without having any side-effect of the unknown uter world, hence a way to retrieve the `.cancel` method internally too, and the reason all promises before the current one, including the current one, will be silently resolved.

No other value than `undefined` came to my mind as default resolution for cancelable promises.
Not sure I've explain myself properly, feel free to ask more or tell me what you think is wrong.

Again, the key here is backward compatible, and the third argument is not the one that resolves or reject, but the one that explicitly expose the ability to be canceled. This is hidden from the outer world, but only if defined, the promise can be canceled: it would throw otherwise (know what you are doing and know what to expect)


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

Received on Monday, 30 March 2015 10:58:21 UTC