Regarding watch channel guarantee and broadcast channel drop value condition. #5948
Unanswered
realzhujunhao
asked this question in
Q&A
Replies: 1 comment
-
You may want to try a broadcast channel that doesn't skip values when it fills up, there should be crates out there with such implementations. Alternatively, you could use many mpsc channels, one for each receiver. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hello, I'm new to tokio async, currently struggling on which channel to use.
I have one producer task and multiple consumer task, each consumer task is going to block (or yield? I'm not sure about correct term) by polling the receiver until its desired value is given.
watch
andbroadcast
channels seem to be suitable for my use case, and since I have only one producer,watch
might be the best fit.For example, suppose my producer task send random chars, consumer task 1 wait until it sees 'A' to proceed the rest of its logic (other chars are ignored but I still want them visible to other consumers).
My concerns with
watch
:I've read through the documentation, it says "A single-producer, multi-consumer channel that only retains the last sent value". Is it possible that a consumer task is not scheduled to run in the time interval producer sends two value? i.e Some consumer task might miss some value.
My concerns with
broadcast
:Doc says "messages must be retained until all handles receive a clone", in my case the desired value for one consumer is not useful for other consumers.
In summary,
watch
andbroadcast
should I use?oneshot Sender
from consumer tasks to producer task, but this will make my code very complicated and I'm not even sure if that works or not.Beta Was this translation helpful? Give feedback.
All reactions