unfetch
unfetch copied to clipboard
Alternative AbortController support (#54)
Resolves #54.
Alternative solution to #68. My implementation differs in the following ways:
- fetch does not override signal's abort handler (one controller can cancel many actions)
- abort results in rejection with DOMExpection and proper error message.
I polyfilled AbortController and AbortSignal in tests, because they do not exist in node env.
To consider:
- will addEventListener prevent GC from clearing unused fetch scopes?
Build:
Build "unfetch" to dist:
556 B: unfetch.js.gz
461 B: unfetch.js.br
558 B: unfetch.mjs.gz
464 B: unfetch.mjs.br
629 B: unfetch.umd.js.gz
525 B: unfetch.umd.js.br
Build "unfetch" to polyfill:
559 B: index.js.gz
466 B: index.js.br
Any movement on this? What can we do to merge this PR?
One thing that is missing here is check if signal is already aborted so unfetch can reject early, and throwing DOMException
won’t work in IE11, so alternative code could be:
try {
abortError = new DOMException('Aborted', 'AbortError');
} catch (err) {
abortError = new Error('Aborted');
abortError.name = 'AbortError';
}