Skip to content

Timeout interruption #2598

Answered by jplatte
SpencerMelo asked this question in Q&A
Discussion options

You must be logged in to vote

Yes, your explanation sounds about right. When the task with the long loop is polled, it blocks the async task which also contains the timeout until it is done. Two obvious solutions come to mind, either you use tokio::task::spawn_blocking (generally preferable for CPU-bound work), or you call tokio::task::yield_now().await periodically within your loop to give back control to give control back to the async runtime / let other futures that are part of the same task make progress.

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by SpencerMelo
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants