Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- use std::process::exit;
- use std::sync::mpsc;
- use std::thread;
- struct Hello {
- text: String,
- }
- impl Hello {
- fn world(&self) {
- println!("{} World", &self.text);
- exit(0);
- }
- }
- fn example() {
- let (tx, rx) = mpsc::channel();
- thread::spawn(move || {
- let ex: Hello = Hello {
- text: String::from("hello"),
- };
- for _ in rx {
- ex.world();
- }
- });
- thread::spawn(move || loop {
- tx.send(()).unwrap();
- });
- }
Add Comment
Please, Sign In to add comment