Replies: 3 comments 5 replies
-
I'm not sure actually. It could probably work to spawn a task that holds the sender and send messages to that via an mpsc channel. Then the task would receive the messages and forward them to the real sender. Then you'd only be cloning the mpsc sender half. However I'm not sure if there is a better way. I recommend asking in #tokio-users in the tokio discord. |
Beta Was this translation helpful? Give feedback.
-
hello, I got another way to get multiple senders of
|
Beta Was this translation helpful? Give feedback.
-
I've created a working example here, since the Arc/Mutex method was still giving me errors about thread safety. https://gist.github.com/hexcowboy/8ebcf13a5d3b681aa6c684ad51dd6e0c |
Beta Was this translation helpful? Give feedback.
-
Following from the websocket chat example provided, we are able to receive messages and send messages independent of each other. My currently use-case would need to take this a step further, where multiple tasks would need to send messages through the same stream.
This will fail as
sender
is moved from the previous loop iteration, I'm not sure as to how you can clone multiple transmitters per-task from a single senderSplitSink
. Is this a common pattern or should another pattern be used entirely (i.e. channels)?Beta Was this translation helpful? Give feedback.
All reactions