-
Notifications
You must be signed in to change notification settings - Fork 38
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rework timer event sources around Poll
The reworks the `Timer` event source to have it directly driven by the core polling of the event loop, instead of relying on external timing mechanisms (like a thread or a timerfd). Fixes #9 Fixes #83 Fixes #84
- Loading branch information
Showing
19 changed files
with
825 additions
and
970 deletions.
There are no files selected for viewing
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
use std::time::{Duration, Instant}; | ||
|
||
use calloop::{ | ||
timer::{TimeoutAction, Timer}, | ||
EventLoop, | ||
}; | ||
|
||
fn main() { | ||
let mut event_loop = | ||
EventLoop::try_new_high_precision().expect("Failed to initialize the event loop!"); | ||
|
||
let before = Instant::now(); | ||
|
||
event_loop | ||
.handle() | ||
.insert_source( | ||
Timer::from_duration(Duration::from_micros(20)), | ||
|_, _, _| TimeoutAction::Drop, | ||
) | ||
.unwrap(); | ||
|
||
event_loop.dispatch(None, &mut ()).unwrap(); | ||
|
||
let elapsed = before.elapsed(); | ||
|
||
println!( | ||
"The event loop slept for {} microseconds.", | ||
elapsed.as_micros() | ||
); | ||
} |
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
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
Oops, something went wrong.