Skip to content
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 our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Alternative AbortController support (#54) #137

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open

Conversation

prk3
Copy link

@prk3 prk3 commented Mar 26, 2020

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

@niksy
Copy link

niksy commented Jun 16, 2020

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';
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

add support for aborting via AbortController
3 participants