How to select!
on a list of Receiver
?
#7314
-
There is a pub struct MultiWatcher<'a, T> {
watches: &'a mut [Receiver<T>],
}
impl<'a, T> MultiWatcher<'a, T> {
pub fn new(watches: &'a mut [Receiver<T>]) -> Self {
Self { watches }
}
/// Return the index of the changed `watches`, or `None` if all channels are closed.
pub async fn wait_next_change(&mut self) -> Option<usize> {
todo!()
}
} |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 4 replies
-
Usually the answer to this question is "do not create multiple channels". You can clone the sender to obtain many senders that send messages to the same receiver. By doing that, you can usually rewrite your code to only have a single receiver. |
Beta Was this translation helpful? Give feedback.
This is my final solution. Thank you very much for telling me the struct
SelectAll
.