Wait! You are blocking the thread! #rustlang #rustprogramming #coding

preview_player
Показать описание
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
Рекомендации по теме
Комментарии
Автор

I was doing this at work and I am ashamed 😄

dario.lencina
visit shbcf.ru