#![cfg(any(target_os = "linux", target_os = "l4re", target_os = "android", target_os = "windows"))]
use {
core::time::Duration,
std::{
io::{Error, ErrorKind},
thread,
time::Instant,
},
crate::{Namaste, Result},
};
pub (crate) const SLEEP_DURATION: Duration = Duration::from_millis(10);
pub fn make<B>(id: B) -> Result<Namaste> where B: AsRef<[u8]> {
Namaste::make(id)
}
pub fn make_wait<B>(id: B, timeout: Duration) -> Result<Namaste> where B: AsRef<[u8]> {
let start = Instant::now();
loop {
match make(&id) {
Ok(namaste) => return Ok(namaste),
Err(_) => {
match Instant::now().checked_duration_since(start) {
Some(duration) => if duration > timeout {
return Err(Error::new(ErrorKind::TimedOut, __!("Timed out")));
},
None => return Err(Error::new(ErrorKind::Other, __!("Invalid system time"))),
};
thread::sleep(SLEEP_DURATION);
},
};
}
}