-
The subscriber is passing data to the receiver channel until the client terminates. let mut sc = connection.subscribe(subject).await.unwrap;
tokio::spawn(async move {
while let Some(m) = sc.next().await {
tx.send(m);
// sc.unsubscribe().await
}
});
// sc.unsubscribe().await Is there any way how to do it? Even if Arc is used, the subscriber cannot acquire the lock outside while waiting for next while holding the lock. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
Unsubscribe is going to happen if the https://docs.rs/tokio/latest/tokio/sync/oneshot/fn.channel.html |
Beta Was this translation helpful? Give feedback.
Unsubscribe is going to happen if the
Subscription
is dropped or by callingunsubscribe()
. You need to signal a Task to unsubscribe and drain messages that are left. This can be done using tokio oneshot channel andselect!
ing both futures.https://docs.rs/tokio/latest/tokio/sync/oneshot/fn.channel.html
https://docs.rs/tokio/latest/tokio/macro.select.html#examples