harshwardhan
Thu Mar 15 2018
Use AbortController to cancel the promise.
/code
const controller = new AbortController();
const signal = controller.signal;
// pass this signal as option in your fetch request
fetch(url, {signal}).then(...).catch(...)
// now you can reject the above promise by calling abort like this
signal.abort()
//promise will get rejected with error "AbortError"
/code
const controller = new AbortController();
const signal = controller.signal;
// pass this signal as option in your fetch request
fetch(url, {signal}).then(...).catch(...)
// now you can reject the above promise by calling abort like this
signal.abort()
//promise will get rejected with error "AbortError"