Wait! You are blocking the thread! #rustlang #rustprogramming #coding
Security Union
If you do this, you are slowing down your system.
Having a CPU-bound function inside a Tokio task effectively blocks the thread, causing a bottleneck.
A cpu bound function is something cpu intensive like encoding audio or solving a complex algorithm.
To fix this, just use tokio::spawn_blocking
This will transfer the blocking call to a separate thread pool dedicated for blocking operations, thereby maintaining the responsiveness of your app.
Join our community for daily tricks on Rust and software engineering ... https://www.youtube.com/watch?v=KRlv4b6NUXI
2023-09-07
0.0 LBC
Copyrighted (contact publisher)
2352544 Bytes