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

Document that runWithClient must be called for every isolate #1069

Merged
merged 2 commits into from
Dec 5, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion pkgs/http/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,9 @@ In Flutter, you can use a one of many
If you depend on code that uses top-level functions (e.g. `http.post`) or
calls the [`Client()`][clientconstructor] constructor, then you can use
[`runWithClient`](runwithclient) to ensure that the correct
`Client` is used.
`Client` is used. When an [Isolate][isolate] is spawned, it does not inherit
any variables from the calling Zone, so `runWithClient` needs to be used in
each Isolate that uses `package:http`.

You can ensure that only the `Client` that you have explicitly configured is
used by defining `no_default_http_client=true` in the environment. This will
Expand Down Expand Up @@ -283,6 +285,7 @@ $ dart compile exe --define=no_default_http_client=true ...
[fetchclient]: https://pub.dev/documentation/fetch_client/latest/fetch_client/FetchClient-class.html
[flutterhttpexample]: https://github.com/dart-lang/http/tree/master/pkgs/flutter_http_example
[ioclient]: https://pub.dev/documentation/http/latest/io_client/IOClient-class.html
[isolate]: https://dart.dev/language/concurrency#how-isolates-work
[flutterstatemanagement]: https://docs.flutter.dev/data-and-backend/state-mgmt/options
[provider]: https://pub.dev/packages/provider
[runwithclient]: https://pub.dev/documentation/http/latest/http/runWithClient.html