Skip to content

Instantly share code, notes, and snippets.

@rust-play
Created June 5, 2019 10:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save rust-play/4cdd9acd65476bf27d0e37d0ea8e53ab to your computer and use it in GitHub Desktop.
Save rust-play/4cdd9acd65476bf27d0e37d0ea8e53ab to your computer and use it in GitHub Desktop.
Code shared from the Rust Playground
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