core-js icon indicating copy to clipboard operation
core-js copied to clipboard

`AbortController` and `AbortSignal`

Open HeberLZ opened this issue 6 years ago • 11 comments

I searched on the issue tracker and repo but didn't find anything about it, are there any plans to add a polyfill for AbortController and AbortSignal? It's primary purpose is to be able to cancel fetch requests, but can also be used manually as a standard mechanism for cancelling promises or any kind of async behavior.

The final version of AbortController has been added to the DOM specification The corresponding PR for the fetch specification is now merged. Browser bugs tracking the implementation of AbortController is available here: Firefox: #1378342, Chromium: #750599, WebKit: #174980, Edge: #13009916.

Current browser support: https://www.caniuse.com/#feat=abortcontroller

HeberLZ avatar Oct 23 '18 22:10 HeberLZ

That does not look like something in the scope of core-js. core-js about ECMAScript spec and cross-platform related features. For canceling promises, I'm waiting for https://github.com/tc39/proposal-cancellation

zloirock avatar Nov 13 '18 20:11 zloirock

Since they have become a de facto standard, I suggest to support them in core-js as well.

FYI: The DOM Standard specification has just been updated (https://github.com/whatwg/dom/pull/1027). It has not yet been implemented on any platform except Deno.

petamoriken avatar Nov 08 '21 17:11 petamoriken

I wanted to reopen this discussion a little later.

zloirock avatar Nov 08 '21 18:11 zloirock

It may be helpful to refer to WinterCG's Minimum Common Web Platform API.

petamoriken avatar Jun 14 '22 13:06 petamoriken

...and this post. Ok, let's reopen this issue.

zloirock avatar Jun 14 '22 13:06 zloirock

It is the scope of core-web: https://github.com/aleen42/core-web/commit/651d3ba271402d862e70a385df239ebfeea9895d

aleen42 avatar Feb 16 '23 02:02 aleen42

@aleen42 thanks, maybe it will be possible to reuse something from that.

zloirock avatar Feb 17 '23 14:02 zloirock

I hacked together a basic polyfill for AbortController/AbortSignal at https://github.com/CaptainPants/zerodeps-multipart-parser/blob/main/src/polyfills/abort.ts. I haven't spent a lot of time on spec compliance, but it might be worth something to the project.

CaptainPants avatar Mar 28 '23 06:03 CaptainPants

AbortSignal.any is probably difficult to implement because it requires iterable weak sets (WeakSet + WeakRef) in spec

https://github.com/whatwg/dom/pull/1152

petamoriken avatar Nov 18 '23 03:11 petamoriken

@petamoriken I have not delved into the features and the specification of this API, but at first glance, it looks like a simple combinator like Promise.any, so I don't see why it's required. Could you explain?

zloirock avatar Nov 18 '23 05:11 zloirock

Ok, I looked at the PR that you mentioned and see what you mean. It's bad, but I don't think that it's a critical problem if in the case of the existence of WeakRef we will have proper garbage collecting of listeners here and in the case of old engines - leaks.

zloirock avatar Nov 18 '23 08:11 zloirock