-
Hi, is it somehow possible to combine two broadcast receivers into one? let (tx1, mut rx1) = broadcast::channel(16);
let (tx2, mut rx2) = broadcast::channel(16);
let rx_all = // Magic with rx1 and rx2
tokio::spawn(async move {
assert_eq!(rx_all.recv().await.unwrap(), 10);
assert_eq!(rx_all.recv().await.unwrap(), 10);
});
tx1.send(10).unwrap();
tx2.send(10).unwrap(); The reason I need this is, that I have multiple receivers but the api I'm using needs a single receiver to be passed to. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
You could turn both receivers into streams and merge the streams, but that's going to give you a stream type, which is not the same as a broadcast receiver. To obtain a broadcast receiver, you could spawn a background task that receives from both channels and forwards messages to a third broadcast channel. There isn't any built-in way in the channel itself. |
Beta Was this translation helpful? Give feedback.
You could turn both receivers into streams and merge the streams, but that's going to give you a stream type, which is not the same as a broadcast receiver. To obtain a broadcast receiver, you could spawn a background task that receives from both channels and forwards messages to a third broadcast channel.
There isn't any built-in way in the channel itself.