Skip to content

When to use different block_on functions? #303

Answered by notgull
ThatGeoGuy asked this question in Q&A
Discussion options

You must be logged in to vote

Really there is no difference. smol::block_on sets up the thread to run the I/O reactor while smol::future::block_on doesn't. However, the I/O reactor can run on its own thread even if smol::block_on isn't running. So functionally there is no difference.

If you care about benchmarks, smol::future::block_on is slightly faster to run if you are blocking on a lot of little futures. So in general I use smol::block_on for long-running futures and smol::future::block_on if I have to block on a tiny one.

If you can't decide it can't hurt to just use smol::block_on.

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@ThatGeoGuy
Comment options

Answer selected by ThatGeoGuy
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