Skip to content

Instantly share code, notes, and snippets.

@rust-play
Created July 5, 2025 14:13
Show Gist options
  • Save rust-play/6849e9e4173b25401aa3f88f9294b60a to your computer and use it in GitHub Desktop.
Save rust-play/6849e9e4173b25401aa3f88f9294b60a to your computer and use it in GitHub Desktop.
Code shared from the Rust Playground
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