I know that promis in js. Are not cancellable but i know genius mind all around the globe must have found some way to make it possible?
comment your answers and let me know...
For further actions, you may consider blocking this person and/or reporting abuse
Top comments (5)
Using 'c-promise2' package we can do the following trick:
(Live Demo - jsfiddle.net/DigitalBrain/c6njyrt9... )
Simple React Demo of using AbortController signal - codesandbox.io/s/react-fetch-class...
Simple React Demo using hooks - codesandbox.io/s/react-cpromise-fe...
Promise cannot be cancelled, it is the process that returns promise must be cancellable.
For example, XmlHttpRequest is cancellable as it has an abort method.
Fetch api also supports AbortController.signal, that is cancellable.
As Promises are deeply nested, and promise is a result, it cannot be cancelled and even if somehow you ignore by putting timeout, underlying process will not be cancelled.
Hi akash i know we cannot cancel the network call but can u tell me how to not perform the action which was suppose to be performed when promise would have resolved?
Think I’ve only seen cancel by timeout with Promise.race[mainPromise, timeoutPromise].
TimeoutPromise throws after a certain amount of time triggering the catch handler of race.
I think to handle a cancellable request you can use RxJS