Skip to content

Instantly share code, notes, and snippets.

@RandyMcMillan
Forked from rust-play/playground.rs
Last active July 5, 2025 14:15
Show Gist options
  • Save RandyMcMillan/c3b8b9a8844e0d0e9de9670c9a854819 to your computer and use it in GitHub Desktop.
Save RandyMcMillan/c3b8b9a8844e0d0e9de9670c9a854819 to your computer and use it in GitHub Desktop.
tokio::sync::mpsc
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