Wait! You are blocking the thread!  #rustlang #rustprogramming #coding
Channel: Dario
Date: 2023-09-07

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