Skip to content

Commit d83794c

Browse files
committed
Adds run_in_mode wrapper over CFRunLoopRunInMode
1 parent f7e0b97 commit d83794c

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

core-foundation/src/runloop.rs

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,14 @@ declare_TCFType!(CFRunLoop, CFRunLoopRef);
2626
impl_TCFType!(CFRunLoop, CFRunLoopRef, CFRunLoopGetTypeID);
2727
impl_CFTypeDescription!(CFRunLoop);
2828

29+
#[derive(Copy, Clone, Debug, PartialEq)]
30+
pub enum CFRunLoopRunResult {
31+
Finished = 1,
32+
Stopped = 2,
33+
TimedOut = 3,
34+
HandledSource = 4,
35+
}
36+
2937
impl CFRunLoop {
3038
pub fn get_current() -> CFRunLoop {
3139
unsafe {
@@ -47,6 +55,24 @@ impl CFRunLoop {
4755
}
4856
}
4957

58+
pub fn run_in_mode(
59+
mode: CFStringRef,
60+
duration: std::time::Duration,
61+
return_after_source_handled: bool,
62+
) -> CFRunLoopRunResult {
63+
let seconds = duration.as_secs_f64();
64+
let return_after_source_handled = if return_after_source_handled { 1 } else { 0 };
65+
66+
unsafe {
67+
match CFRunLoopRunInMode(mode, seconds, return_after_source_handled) {
68+
2 => CFRunLoopRunResult::Stopped,
69+
3 => CFRunLoopRunResult::TimedOut,
70+
4 => CFRunLoopRunResult::HandledSource,
71+
_ => CFRunLoopRunResult::Finished,
72+
}
73+
}
74+
}
75+
5076
pub fn stop(&self) {
5177
unsafe {
5278
CFRunLoopStop(self.0);

0 commit comments

Comments
 (0)