Created
January 2, 2019 02:22
-
-
Save Fullstop000/4f87fa7588c291f17a2905328ce4379a to your computer and use it in GitHub Desktop.
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 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