Files
system76-embedded-controller/tool/src/timeout.rs
2020-02-20 21:09:10 -07:00

28 lines
648 B
Rust

#[macro_export]
macro_rules! timeout {
($t:expr, $f:expr) => {{
let mut result = Err($crate::Error::Timeout);
while $t.running() {
match $f {
Ok(ok) => {
result = Ok(ok);
break;
},
Err(err) => match err {
$crate::Error::WouldBlock => (),
_ => {
result = Err(err);
break;
}
},
}
}
result
}};
}
pub trait Timeout {
fn reset(&mut self);
fn running(&self) -> bool;
}