-
-
Save RandyMcMillan/c3b8b9a8844e0d0e9de9670c9a854819 to your computer and use it in GitHub Desktop.
tokio::sync::mpsc
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use tokio::sync::mpsc; | |
//use tokio::time::{Duration, sleep}; | |
#[tokio::main] | |
async fn main() { | |
let (tx, mut rx) = mpsc::channel(100); | |
tokio::spawn(async move { | |
for i in 0..10 { | |
tx.send(format!("event {}", i)).await.unwrap(); | |
} | |
}); | |
while let Some(msg) = rx.recv().await { | |
println!("Received: {}", msg); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment