Created
June 5, 2019 10:31
-
-
Save rust-play/4cdd9acd65476bf27d0e37d0ea8e53ab to your computer and use it in GitHub Desktop.
Code shared from the Rust Playground
This file contains 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::thread; | |
use std::sync::mpsc; | |
use std::time; | |
fn main() { | |
let (tx, rx) = mpsc::channel(); | |
thread::spawn(move || { | |
let val = String::from("hi"); | |
thread::sleep(time::Duration::from_millis(100)); | |
tx.send(val).unwrap(); | |
}); | |
loop { | |
match rx.try_recv() { | |
Ok(r) => { | |
println!("Got: {}", r); | |
break; | |
}, | |
Err(err) => { | |
println!("Waiting..."); | |
thread::sleep(time::Duration::from_millis(10)); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment