-
-
Save rust-play/6849e9e4173b25401aa3f88f9294b60a to your computer and use it in GitHub Desktop.
Code shared from the Rust Playground
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