Skip to content

tokio::select! how to handle multiple branch. #4222

Answered by Darksonn
kenmasumitsu asked this question in Q&A
Discussion options

You must be logged in to vote

If you have a variable number of streams, then you shouldn't be using select!. Here are some other options:

  1. Have all the senders send to the same receiver so you only have to receive from one thing.
  2. Use tokio_stream::StreamMap.
  3. Use futures::stream::SelectAll.

The difference between option 2 and 3 is whether it tells you which receiver the message came from.

Replies: 2 comments 3 replies

Comment options

You must be logged in to vote
3 replies
@kenmasumitsu
Comment options

@Darksonn
Comment options

@kenmasumitsu
Comment options

Answer selected by kenmasumitsu
Comment options

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