Replies: 1 comment
-
Question in title: There was a PR to add that feature, but there was some issue with it so it was closed. Somebody could make a new PR if they wanted. Question in body: Graceful shutdown is covered in this chapter. A watch channel can be used instead of broadcast as well. Note regarding crossbeam: Crossbeam is a blocking channel, so you can't use it in async code. Read more here. |
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
Uh oh!
There was an error while loading. Please reload this page.
-
Hi. Previously I've use crossbeam channels like a signal to stop between threads (MPMC). Explanation:
I have thread#1 and tokio_task#1, in tokio_task#1 I have a loop with function call. After creating crossbeam_channel I send Sender to thread#1 and receiver in tokio_task#1. Because of loop in tokio_task#1 I need be able to clone receiver, which crossbeam let's me to do. So when thread#1 is exits - tokio_task#1 see that and exits too and vise versa.
But as I found, this might make troubles when using crossbeam receiver in tokio task, so I choose to use tokio broadcast channel and now I've stuck, because I can't clone receiver directly. Instead I must send Sender to tokio_task#1 and on every iteration of loop call to sender.subscribe(). The problem here is when thread#1 is exits - there is still alive 1 receiver and 1 sender in tokio_task#1, so tokio task can't determine that he needs to exit. Crossbeam let's me to just call .clone() on receiver and that's it, and when thread#1 is exits - I've no Senders alive.
I've feeling that this is not best aproach to bind thread and task together, or different threads, or even two long tasks, can u suggest me for more correct approach to bind threads/tasks together, so that when one exits, all exits too? Or how to deal here with channels in tokio?
Beta Was this translation helpful? Give feedback.
All reactions