Experiment with fetch higher order functions and abortability
I based my code on this CancelToken proposal.
What I didn't like on that proposal is that there is no handy way to get the CancelError
:
- You can wrap
throwIfRequested()
in a try/catch to get the exception - You can
promise.then()
to get the CancelToken, but then you have to take the asynchronicity into account.
Instead of promise
, I used a subscribe
function that returns an unsubscribe function.
You pass an onCancel callback that will be called with the CancelError
only once when cancel is called or when it is already cancelled at subscribe.
Here an example where I prefer to get the CancelError synchronous.