Created
April 22, 2019 23:39
-
-
Save pusateri/58ea591219ce2a90166daee811c3dbbb to your computer and use it in GitHub Desktop.
mio extra timers don't fire
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::time::Duration; | |
use mio::{Events, Ready, Poll, PollOpt, Token}; | |
use mio_extras::channel; | |
use mio_extras::timer::Timer; | |
fn main() { | |
const CHANNEL: Token = Token(0); | |
let poll = Poll::new().unwrap(); | |
let (tx, rx) = channel::channel::<u32>(); | |
let mut events = Events::with_capacity(1024); | |
let mut tok = 1; | |
tx.send(1).unwrap(); | |
poll.register(&rx, CHANNEL, Ready::readable(), PollOpt::edge()).unwrap(); | |
loop { | |
poll.poll(&mut events, None).expect("poll.poll failed"); | |
for event in events.iter() { | |
println!("event"); | |
if event.token() == CHANNEL { | |
let _t: u32 = rx.try_recv().unwrap(); | |
let when = Duration::from_secs(2); | |
let mut timer = Timer::default(); | |
let timer_token = Token(tok); | |
println!("channel tok: {} when: {:?}", tok, when); | |
timer.set_timeout(when, tok); | |
tok += 1; | |
poll.register(&timer, timer_token, Ready::readable(), PollOpt::edge()).unwrap(); | |
} else { | |
println!("timer: {:?}", event) | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment