You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Currently it is only implemented in Firefox 57 and is coming to other browsers soon.
constcontroller=newAbortController();constsignal=controller.signal;setTimeout(()=>controller.abort(),5000);fetch(url,{ signal }).then(response=>{returnresponse.text();}).then(text=>{console.log(text);});
Will most likely need to implement another npm package that just include AbortController package. I found one but it also pollyfills fetch. https://github.com/mo/abortcontroller-polyfill
Reacted by Tejesh Mehta, Shannon Moeller 🧢, Nina Kitsu, John Schottler, Nicolás Fantone, Jafar Rezaei, Abraham Schilling and Sergey
So we'd need a new npm package that exports a standalone polyfill for AbortController, and then the only modifications needed to unfetch would be to proxy signal.onabort = request.abort. Seems like it might be doable in a few bytes.
As of 2019, https://caniuse.com/#search=abort AbortController is supported by 86% of browser users. But I'm not sure if AbortController is available for use with XMLHttpRequest. But there's an alternative since that req object already has an .abort API.
So perhaps there can be a way expose the request's XMLHttpRequest.abort method to the caller from the promise wrapper. Although I'm unsure how you'd return that in the context of a Promise since resolve is only allowed to be called once. https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest/abort
Any movements on this? With all major green browsers supporting it, AbortController is steadily becoming the norm with many sources and docs out there showing people how to use it. Would be nice to have it baked into unfetch.
node-fetch is actively recommending abort-controller. At least one of the PRs will bring support. What's preventing movement on this? What's everyone using in the meantime?
Activity
developit commentedon Oct 20, 2017
So we'd need a new npm package that exports a standalone polyfill for
AbortController, and then the only modifications needed to unfetch would be to proxysignal.onabort = request.abort. Seems like it might be doable in a few bytes.prabirshrestha commentedon Oct 20, 2017
Awesome. Could you post the link to the npm package?
Jador commentedon Oct 30, 2017
@prabirshrestha here's one https://www.npmjs.com/package/abortcontroller-polyfill
prabirshrestha commentedon Mar 22, 2018
Chrome 66 beta seems to officially support it. https://blog.chromium.org/2018/03/chrome-66-beta-css-typed-object-model.html
Add support for AbortController (developit#54)
lxsmnsyc commentedon Apr 12, 2019
An implementation of WHATWG AbortController interface.
https://github.com/mysticatea/abort-controller
dangdennis commentedon Nov 10, 2019
As of 2019, https://caniuse.com/#search=abort AbortController is supported by 86% of browser users. But I'm not sure if AbortController is available for use with XMLHttpRequest. But there's an alternative since that req object already has an
.abortAPI.So perhaps there can be a way expose the request's
XMLHttpRequest.abortmethod to the caller from the promise wrapper. Although I'm unsure how you'd return that in the context of a Promise sinceresolveis only allowed to be called once. https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest/abortEdit:
Nevermind, someone already solved it using event emitters.
https://codesandbox.io/s/92vnjok08r
JohnnyFun commentedon Jan 10, 2020
You could also just add an
abortfunction on the returned promise. Hacky, but works.nfantone commentedon Feb 11, 2020
Any movements on this? With all major green browsers supporting it,
AbortControlleris steadily becoming the norm with many sources and docs out there showing people how to use it. Would be nice to have it baked intounfetch.mikestopcontinues commentedon Nov 30, 2020
node-fetchis actively recommending abort-controller. At least one of the PRs will bring support. What's preventing movement on this? What's everyone using in the meantime?