FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

AbortController ponyfill by stereobooster · Pull Request #94 · developit/unfetch · GitHub

Repository navigation

AbortController ponyfill - #94

Closed
stereobooster wants to merge 1 commit into
developit:masterfrom
stereobooster:abort-controller
Closed

stereobooster wants to merge 1 commit into
developit:masterfrom
stereobooster:abort-controller

Conversation

stereobooster commented Sep 29, 2018 •
edited
Loading

Copy link
Copy Markdown

Comment thread src/index.mjs
request.onerror = reject;

if (options.signal) options.signal.onabort = () => { request.abort(); }
request.onabort = () => reject(new DOMException('The user aborted a request.'));

stereobooster Sep 29, 2018 •
edited
Loading

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

this is to simulate what Chrome does, but i don't insist on it

joaovieira Oct 3, 2018 •
edited
Loading

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

per the spec (even that chrome exception has a name of AbortError):

reject(new DOMException('Aborted', 'AbortError'));

https://dom.spec.whatwg.org/#aborting-ongoing-activities
https://dom.spec.whatwg.org/#aborting-ongoing-activities-example
https://github.com/github/fetch/blob/master/fetch.js#L446

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

I wonder what browsers don't have it. I can't find data about this in caniuse. Shall we use Error instead?

Comment thread src/AbortController.mjs
@@ -0,0 +1,6 @@
export default function() {
this.signal = { onabort: () => {} };

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Comment thread src/index.mjs
request.onerror = reject;

if (options.signal) options.signal.onabort = () => { request.abort(); }
request.onabort = () => reject(new DOMException('The user aborted a request.'));

joaovieira Oct 3, 2018 •
edited
Loading

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

per the spec (even that chrome exception has a name of AbortError):

reject(new DOMException('Aborted', 'AbortError'));

https://dom.spec.whatwg.org/#aborting-ongoing-activities
https://dom.spec.whatwg.org/#aborting-ongoing-activities-example
https://github.com/github/fetch/blob/master/fetch.js#L446

Comment thread src/index.mjs

request.onerror = reject;

if (options.signal) options.signal.onabort = () => { request.abort(); }

joaovieira Oct 3, 2018 •
edited
Loading

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Copy link
Copy Markdown
Author

Thanks for links to fetch spec.

I got the idea of passing aborted signal to the fetch, but I wonder what the use case? In what kind of API you would create N-signals and attach to fetch later? I create signal right before sending request and save it until I got response, to be able to cancel if I need to create another fetch (and only one allowed at the same time).

Should be trivial to implement, I just wonder do we need it or not

Copy link
Copy Markdown

@stereobooster I also didn't have that use case yet. But I can think of using it as a hand-rolled circuit-breaking system where you use a signal to reject all requests going to a troubled/struggling downstream service.

Anyway, many people will use unfetch with isomorphic-unfetch so having consistent functionality with node-fetch (and thus, the spec) sounds right. Specially if it's easy :)

Copy link
Copy Markdown
Author

Anyway, many people will use unfetch with isomorphic-unfetch so having consistent functionality with node-fetch (and thus, the spec) sounds right.

The point of unfetch it is minimal implementation, it is not fully compatible with spec and never meant to be. It is just subset of spec. The question is where to draw the line. I would say we need to support popular case only

This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
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.

2 participants


Back | FazBrowse Home | New Git URL