Skip to content

Commit cd748b6

Browse files
authored
Document that runWithClient must be called for every isolate (#1069)
1 parent f585947 commit cd748b6

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

pkgs/http/README.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,9 @@ In Flutter, you can use a one of many
255255
If you depend on code that uses top-level functions (e.g. `http.post`) or
256256
calls the [`Client()`][clientconstructor] constructor, then you can use
257257
[`runWithClient`](runwithclient) to ensure that the correct
258-
`Client` is used.
258+
`Client` is used. When an [Isolate][isolate] is spawned, it does not inherit
259+
any variables from the calling Zone, so `runWithClient` needs to be used in
260+
each Isolate that uses `package:http`.
259261

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

0 commit comments

Comments
 (0)