You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The AbortController interface represents a controller object that allows you to abort one or more Web requests as and when desired.
But it's not constrained to only work with "Web requests"; Anders links to a Google developer doc that says this:
It's deliberately generic so it can be used by other web standards and JavaScript libraries.
This sounds like it's not an abomination to use it for more basic control-flow needs that have nothing to do with fetch or its friends. In particular, we can use this mechanism to break out of the while (true) loop in tryUntilSuccessful (soon to be renamed to tryFetch in, I think, #4166), when we want to abort. (In that PR, that particular need is answered with a local stateful boolean variable—it's nice to know there's a standard, well-documented way of doing it.)
And, of course, we'll actually be able to abort fetch requests.
Fingers are crossed that this React Native polyfill works; there's some history of RN-shipped polyfills being buggy.
The text was updated successfully, but these errors were encountered:
I think the article linked from this tweet from Dan Abramov is probably worth reading, at least in part, if only just because it's Dan Abramov. I haven't read it yet. To quote the tweet:
I should probably clarify the technical aspect that I don’t earnestly believe Promises should be cancelable. It doesn’t work with the read-only design. If you’re interested in reasonable modern approaches to cancellation, this is a good read. https://vorpus.org/blog/timeouts-and-cancellation-for-humans/
I've just filed #4659 for an implementation plan to expose easy methods for canceling fetches; after that work is done, we'll just have to call those methods in the right places. (tryFetch after #4193 may be such a place.)
See discussion (thanks @andersk for pointing this out, and @gnprice for nudging me to look closer!).
With facebook/react-native#24419, React Native (v0.60) gained a polyfill for the
AbortController
Web API; see the MDN doc.The MDN doc leads with this:
But it's not constrained to only work with "Web requests"; Anders links to a Google developer doc that says this:
This sounds like it's not an abomination to use it for more basic control-flow needs that have nothing to do with
fetch
or its friends. In particular, we can use this mechanism to break out of thewhile (true)
loop intryUntilSuccessful
(soon to be renamed totryFetch
in, I think, #4166), when we want to abort. (In that PR, that particular need is answered with a local stateful boolean variable—it's nice to know there's a standard, well-documented way of doing it.)And, of course, we'll actually be able to abort
fetch
requests.Fingers are crossed that this React Native polyfill works; there's some history of RN-shipped polyfills being buggy.
The text was updated successfully, but these errors were encountered: