Skip to content

Instantly share code, notes, and snippets.

@gliheng
Created January 14, 2019 01:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gliheng/cfb83992297dd2cd26a06e1ffce86135 to your computer and use it in GitHub Desktop.
Save gliheng/cfb83992297dd2cd26a06e1ffce86135 to your computer and use it in GitHub Desktop.
Send closures to anther thread
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