-
-
Notifications
You must be signed in to change notification settings - Fork 2.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Problem with tokio::sync::watch channel behavior #3643
Comments
This is because, by dropping the future returned by |
@Darksonn Thank you so much! Resolved. use tokio::sync::watch;
use tokio_stream::{wrappers::WatchStream, StreamExt};
#[tokio::main]
async fn main() {
let (tx, rx) = watch::channel("hello");
let mut stream = WatchStream::new(rx).map(|payload| {
println!("{}", payload);
});
stream.next().await;
tx.send("goodbye").unwrap();
stream.next().await;
} |
@Darksonn awaiting #[tokio::main]
async fn main() {
let (tx, rx) = watch::channel("hello");
let mut stream = WatchStream::new(rx).map(|payload| {
println!("{}", payload);
});
let task = tokio::spawn(async move {
loop {
stream.next().await;
}
});
tx.send("goodbye").unwrap();
task.await.ok();
} output: goodbye
goodbye |
Ah, there's a good reason for that to happen, but it would be nice to fix. Can you open a new bug-report with just that? |
Sure, #3655. |
Version
$ cargo tree | grep tokio └── tokio v1.4.0 └── tokio-macros v1.1.0 (proc-macro)
Platform
$ uname -a Linux dev 5.4.0-67-generic #75~18.04.1-Ubuntu SMP Tue Feb 23 19:17:50 UTC 2021 x86_64 x86_64 x86_64 GNU/Linux
Description
Watch channel's receiver half cloned and polled inside a Stream. but it not working as expected.
The expected behavior is like using the normal receiver channel.
The text was updated successfully, but these errors were encountered: