- Notifications
You must be signed in to change notification settings - Fork202
Add support for AbortController (#54)#68
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
base:main
Are you sure you want to change the base?
Conversation
I'm not sure this failed because of my PR? Test seems unrelated? |
Right, I see PR#67 resolves the failing tests |
stereobooster commentedMay 24, 2018
functionAbortController(){this.signal={onabort:()=>{}}this.abort=()=>{this.signal.onabort()}} |
@stereobooster I'm kinda wondering if that piece is required to make this PR usable TBH. I love the idea of keeping things split up, but we should probably just make a call on either supporting or not supporting abort. If we say it's important enough, probably best to install that polyfill (though it pains me). |
stereobooster commentedJul 20, 2018
@developit yes it is required, if browser doesn't provide On the other hand this polyfill (
Because of this inconsistency I end upusing your code as ponyfill. |
I'm not convinced that it's required that we actually provide the AbortController polyfill. I know it's required for the abort feature to actually work, but adding those extra bytes for everyone for only a maybe use case kind of goes against the purpose of a tiny fetch polyfill/ponyfill. We can just say that support for abort requires an appropriate polyfill (like libs do with Promises) and point them elsewhere OR provide the above as a separate export in this module? I have usedhttps://www.npmjs.com/package/abortcontroller-polyfill with this modified version of unfetch as a ponyfill to ensure consistent abort behaviour. |
developit commentedSep 13, 2018 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
Another option would be to export AbortController separately: importfetchfrom'unfetch';importAbortControllerfrom'unfetch/AbortController'; I've been thinking of doing the same for |
@developit how are you thinking of doing that? I mean would you import and use the Request, Response and Headers implementations directly in the main unfetch function? Seems like that could be a lot of extra bytes... Or are you imagining them as completely separate entities? |
joaovieira commentedOct 2, 2018 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
This has been discussed in whatwg-fetch as well before, starting fromJakeChampion/fetch#592 (comment). You might also want to look athttps://github.com/Netflix/yetch/blob/master/polyfill.js. It polyfills fetch wether it doesn't exist or wether it doesn't support abort controller. My personal opinion as a user is what I mentioned inJakeChampion/fetch#592 (comment) - the fetch polyfill to implement entire fetch or add the missing parts ( Lastly, why re-implement |
MrLoh commentedJan 8, 2020
Will this ever be merged, seems like the discussion got stuck. |
nfantone commentedFeb 11, 2020 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
Don't mean to be impetuous here, but - maybe we are overthinking this? We've been discussing it for almost two years. This is, literally, addingtwo lines of code to support something all major browser already do. |
@nfantone AbortController is pretty well-supported now, yes. At the time of this original discussion it was only supported in Chrome. I think now we can merge this - unfetch is likely to get a little bump up in size in order to accomodate the addition of |
prk3 commentedMar 5, 2020
There might be a problem with this implementation. With native fetch, many requests can be cancelled with one abort call. If we override constctl=newAbortController();fetch('foo',{signal:ctl.signal}).then(action1).catch(()=>{});fetch('bar',{signal:ctl.signal}).then(action2).catch(()=>{});ctl.abort();
constcurrent=options.signal.onabort||()=>{};options.signal.onabort=()=>{current();request.abort();} I am not sure about side-effects of this one though. |
sayjeyhi commentedMar 17, 2020 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
Any update? |
prk3 commentedMar 26, 2020
@developit@sayjeyhi I submitted PR#137 with alternative implementation. It solves problems I mentioned earlier at a cost of build size. If you decide to merge this (#68) PR without changes, please add a note to the README explaining what to expect from abort behaviour. |
I think the two issues addressed in#137 make it preferable here - AbortController should be usable across multiple fetch() calls, and it should really reject with a value, since promise handlers are likely to be checking for such a value. |
mfuentesg commentedJul 17, 2020
Will this ever be merged? :( |
Resolves#54