AbortController Polyfill for Node.JS based on EventEmitter
const controller =const signal = controllersignalawait// Abort after 500ms. Effectively a timeout
Why would I use this?
- Modern Browsers (Not Internet Explorer)
- Legacy Browsers (Mostly Internet Explorer)
For modern JS APIs, each environment would ideally get a polyfill:
- only if it needs one
- specific to the platform.
In practice, this is hard. Tooling such as webpack and browserify are great at making sure stuff works out of the box in all environments. But it is quite easy to fail on both points above. In all likelyhood, you end up shipping less than ideal polyfills on platforms that don't even need them. So what is a developer to do? In the case of
AbortController I've done the work for you. This is a guide to that work.
If you are building a ...
Application running in modern browsers:
Congrats! You don't need a library or polyfill at all! Close this tab. Uninstall this package.
Application running in modern browsers AND node (such as a server side rendered JS app):
Use this package and node-fetch. It is minimally what you need.
Application supporting legacy browsers AND NOT node:
Application supporting legacy browsers AND node:
Library being consumed by other applications and using
Use this package and node-fetch. It is the smallest and least opinionated combination for your end users. Application developers targeting Internet Exploer will need to polyfill
fetch on their own. But your library won't be forcing unecessary polyfills on developers who only target modern browsers.
With the above guide in mind, this library has a very specific set of goals:
- Provide a minimal polyfill in node.js
- Do not provide a polyfill in any browser environment
This is the ideal for library authors who use
AbortController internally and target both browser and node developers.
Thank you @mysticatea for https://github.com/mysticatea/abort-controller. It is a fantastic
AbortController polyfill and ideal for many use cases.