Last active
April 11, 2023 10:22
-
-
Save thorseraq/3f366e5aff2ed2f2b17d2954071840ce to your computer and use it in GitHub Desktop.
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 std::sync::Arc; | |
| use std::thread::sleep; | |
| use std::time::Duration; | |
| use tokio::sync::RwLock; | |
| #[tokio::main] | |
| async fn main() { | |
| let (tx, mut rx) = tokio::sync::mpsc::channel::<i32>(100); | |
| for i in 0..100 { | |
| tx.send(i).await.expect("TODO: panic message"); | |
| } | |
| let rx = Arc::new(RwLock::new(rx)); | |
| { | |
| let rx = rx.clone(); | |
| tokio::spawn(async move { | |
| while let Some(message) = rx.write().await.recv().await { | |
| println!("GOT {}", message); | |
| } | |
| }); | |
| } | |
| sleep(Duration::from_secs(10)); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment