-
The example https://github.com/tokio-rs/tokio/blob/master/examples/chat.rs#L203 shows me that To ensure all the data can be handled, I have to do this. tokio::select! {
_ = async {
loop {
// some works
}
} => {}
_ = async {
loop {
// some works
}
} => {}
} Is it correct? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
The |
Beta Was this translation helpful? Give feedback.
The
tokio::select!
runs the branches you provide it concurrently, but not in parallel. This means that only one branch can do work at any time, and that the macro will alternate between doing work on the branches. Because of this non-parallel approach, it can't happen that two branches become ready at the same time, so e.g. in the linked example, it is not possible to lose a line from the peer because you got a message frompeer.rx
at the same time.