Skip to content

Instantly share code, notes, and snippets.

@Fullstop000
Created January 2, 2019 02:22
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 Fullstop000/4f87fa7588c291f17a2905328ce4379a to your computer and use it in GitHub Desktop.
Save Fullstop000/4f87fa7588c291f17a2905328ce4379a to your computer and use it in GitHub Desktop.
use mio::{Handler, EventLoop};
use std::{thread, time};
fn main() {
let mut event_loop = EventLoop::<MyHandler>::new().unwrap();
let sender = event_loop.channel();
let sender2 = sender.clone();
thread::spawn(move || {
loop {
thread::sleep(time::Duration::from_secs(1));
match sender.send(1) {
Ok(()) => (),
Err(e) => println!("{:?}", e),
}
}
});
thread::spawn(move || {
loop {
thread::sleep(time::Duration::from_millis(800));
match sender2.send(2) {
Ok(()) => (),
Err(e) => println!("{:?}", e),
}
}
});
event_loop.run(&mut MyHandler).unwrap();
}
struct MyHandler;
impl Handler for MyHandler {
type Timeout = u64;
type Message = u64;
fn notify(&mut self, event_loop: &mut EventLoop<Self>, msg: Self::Message) {
println!("notify {}", msg);
}
fn timeout(&mut self, event_loop: &mut EventLoop<Self>, timeout: u64) {
println!("timeout {}", timeout);
}
fn tick(&mut self, event_loop: &mut EventLoop<Self>) {
println!("tick!");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment