Created
January 14, 2019 01:48
-
-
Save gliheng/cfb83992297dd2cd26a06e1ffce86135 to your computer and use it in GitHub Desktop.
Send closures to anther thread
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::sync::mpsc::channel; | |
use std::thread; | |
fn main() { | |
let (tx, rx) = channel::<Box<dyn Fn() + Send>>(); | |
thread::spawn(move || { | |
let _ = tx.send(Box::new(|| { | |
println!("wtf"); | |
})); | |
let _ = tx.send(Box::new(|| { | |
println!("wtf123"); | |
})); | |
}); | |
for x in rx { | |
x(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment