Skip to content
This repository was archived by the owner on Sep 26, 2022. It is now read-only.
This repository was archived by the owner on Sep 26, 2022. It is now read-only.

Abort requests on native targets #189

Open

Description

@jeromebon

Is your feature request related to a problem? Please describe.
On the web, fetch have an abort mechanisms, the AbortSignal
According to the documentation there is the webFetchExtra parameter which accept a signal.
But there doesn't seem to be an equivalent for native targets. Is this by design or an oversight?

I usually abort requests in React's useEffect to avoid the "Can't perform a React state update on an unmounted component" error. For example:

useEffect(() => {
  const abortController = new AbortController()
  fetch(url, { signal: abortController.signal })
    .then(data => {
      setState(data)
    })
  return abortController.abort
}, [])

Describe the solution you'd like
For the native targets to support the signal parameter, which would accept an AbortSignal instance such as on the web.
Or for Http.request (get, post, etc) to return both the response's Promise and a cancel method.

Describe alternatives you've considered
Implementing abort on top of Http by wrapping the Http promise in an other Promise which reject whenever the signal emit the abort event

Activity

  1. dfidalg0 commented on Nov 10, 2021

    @dfidalg0

    I left a PR (#193) trying to solve this. It's actually a little complicated 😅, since we need to track down the abortable requests and close their respective sockets. Currently, it's not working on iOS, though.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions