DEV Community

Discussion on: How to cancel a promise in javascript ?

Collapse
 
akashkava profile image
Akash Kava

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.

Collapse
 
wierdorohit123 profile image
rohit raut

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?