How to handle long running blocking calls? #2045
-
What is the correct way to run blocking calls that could possibly take more time? Is there a way to configure a separate thread pool that handle these? Also be able to specify the pool size.
|
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 1 reply
-
It looks like the request will wait for the task to finish, right? The "default" way to do this is to use You can also totally use a separate threadpool for this, as long as you asynchronously wait for the task. |
Beta Was this translation helpful? Give feedback.
-
@syphar thanks for the answer. Can you please provide the axum handler code that uses [tokio::task::spawn_blocking]? I'm a complete rust noob and that will help a lot. |
Beta Was this translation helpful? Give feedback.
It looks like the request will wait for the task to finish, right?
The "default" way to do this is to use
tokio::task::spawn_blocking
, which uses a separate threadpool, with configurable size.You can also totally use a separate threadpool for this, as long as you asynchronously wait for the task.