Why is tokio::task::block_in_place() a bad idea? + other async questions
#12510
-
|
Hello! Main QuestionI was reading the docs for
near the bottom. Why is it a bad idea? My thought would be to use I like the idea of this because I would be able to have multi-threaded async stuff without having to think about it. I could just Am I missing something here? Side Questions
Thanks! |
Beta Was this translation helpful? Give feedback.
Replies: 4 comments 4 replies
-
|
Because So the
Because we use winit, because we need an event loop that integrate with the windowing system's event loop.
Yes it is. 100% |
Beta Was this translation helpful? Give feedback.
-
|
@drewlwhitney |
Beta Was this translation helpful? Give feedback.
-
|
@sandreas perhaps it is better to explicitly create the runtime rather than using |
Beta Was this translation helpful? Give feedback.
-
|
I personally don't think that tokio is a bad idea in general. AFAIK only #[tokio:main] is discouraged. In my sample I create a tokio runtime manually, extract the handle and operate on a clone of the handle or in case of the UI thread on the original. This seems to work fine, although I must say that using libraries that may be blocking (e.g. Tokio might no longer switch threads when a loop is used within a This was a very painful lesson since |
Beta Was this translation helpful? Give feedback.
@drewlwhitney
I personally don't think that tokio is a bad idea in general. AFAIK only #[tokio:main] is discouraged.
In my sample I create a tokio runtime manually, extract the handle and operate on a clone of the handle or in case of the UI thread on the original. This seems to work fine, although I must say that using libraries that may be blocking (e.g.
evdev) is a bit tricky.Tokio might no longer switch threads when a loop is used within a
tokio::spawnand results in never finishing work / deadlock. So my personal approach now is to usetokio::spawnfor all crates that officially support tokio (likesea-orm) and to usestdfor everything else, because std creates REAL threads.This w…