Why does it seem async client not reusable across tasks? #2075
-
I want to reuse the async client across multiple tasks, but I am encountering blocking issues. In Code-A, after executing print_main_page, subsequent await calls in the main function lead to deadlocks. Code-A
Code-A output:
When I move the initialization of the async client into the print_main_page function (meaning the async client is not reused), the code does not block. Code-B
Code-B outout:
Is this caused by my incorrect usage? Thanks for any help! |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
There's nothing in Could the |
Beta Was this translation helpful? Give feedback.
There's nothing in
reqwest::Client
that is blocking, you should be able to use it across multiple tasks.Could the
loop {}
in your spawned task be the problem? It will never yield, and if you're using a single threaded Tokio runtime, then when it's looping forever, the other task can never run.