diff --git a/Cargo.toml b/Cargo.toml index 98f0eb2..1872118 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,5 +1,5 @@ [package] -name = "aftermath" +name = "aftermath-rs" version = "0.1.0" edition = "2021" diff --git a/src/lib.rs b/src/lib.rs index c593afd..ed42f8e 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -56,6 +56,7 @@ impl Drop for Aftermath { } } +#[derive(Debug, PartialEq, Eq)] pub enum Status { NotStarted = 0, CollectingData, @@ -73,6 +74,17 @@ impl Status { std::mem::transmute(status) } } + pub fn wait_for_status(timeout: Option) -> Self { + let mut status = Self::get(); + let delta = std::time::Duration::from_millis(50); + let mut time = std::time::Duration::new(0, 0); + while status != Status::CollectingDataFailed && status != Status::Finished && timeout.map_or(true, |t| time < t) { + std::thread::sleep(delta); + time += delta; + status = Self::get(); + } + status + } } pub trait AftermathDelegate: Send + Sync + 'static {