Skip to content

What is the main thread doing when calling runtime.block_on? #6831

Answered by Darksonn
eladm-ultrawis asked this question in Q&A
Discussion options

You must be logged in to vote
  1. When using multi-thread runtime, the thread calling block_on will only execute the single future you passed to it. No other tasks execute on that thread.
    • With a multi-thread runtime, you should generally move your server listener into a tokio::spawn task rather than block_on so that it can run within the general pool, rather than being pinned to the block_on thread.
    • When using the current-thread runtime, this is different. That runtime spawns no worker threads, and runs all tasks inside the block_on call. The current-thread runtime does not execute tasks at all unless there is a call to block_on.
  2. A Tokio runtime never has more than one thread waiting on the IO completion port. Other t…

Replies: 1 comment 2 replies

Comment options

You must be logged in to vote
2 replies
@eladm-ultrawis
Comment options

@Darksonn
Comment options

Answer selected by eladm-ultrawis
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