Closed wanyt closed 1 month ago
Why do you feel this approach consumes excessive CPU? Have you measured this?
Why do you even need a loop here? The recv.read_to_end()
call should yield only once, after the entire response is available. In fact, polling this future more than once will probably yield undefined behavior.
How should I continuously wait to receive data when I'm not sure when the data will come?
Your async runtime will wake up your task when data has been received. But this is the basics of async Rust, and I don't think our issue tracker is the right place to explain the whole paradigm.
In an MQTT communication scenario based on Quinn, the client needs to wait for data being sent by the server. How can the client wait to receive the data from the server? I am currently using a loop, but I feel that this approach consumes CPU resources excessively. Is there a way for the client to block and receive data?
this is my code: