From e7b8242b4967c0227d773d1c2e6fb123ffbdd4a1 Mon Sep 17 00:00:00 2001 From: Brian Quinlan Date: Mon, 4 Dec 2023 15:52:47 -0800 Subject: [PATCH 1/2] Clarify that runWithClient must be called for every isolate --- pkgs/http/README.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/pkgs/http/README.md b/pkgs/http/README.md index 8ce106d43e..a349825195 100644 --- a/pkgs/http/README.md +++ b/pkgs/http/README.md @@ -255,7 +255,8 @@ 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. Since [isolates][isolate] cannot share mutable state, you +must call [`runWithClient`](runwithclient) at the start of every isolate. 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 @@ -283,6 +284,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 From 36bb9853ca7ee261ac27ecf289e01d23bc2a07ff Mon Sep 17 00:00:00 2001 From: Brian Quinlan Date: Mon, 4 Dec 2023 16:21:26 -0800 Subject: [PATCH 2/2] Update README.md --- pkgs/http/README.md | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/pkgs/http/README.md b/pkgs/http/README.md index a349825195..157a52f678 100644 --- a/pkgs/http/README.md +++ b/pkgs/http/README.md @@ -255,8 +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. Since [isolates][isolate] cannot share mutable state, you -must call [`runWithClient`](runwithclient) at the start of every isolate. +`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