pub async fn wait<T, E, F, R>(options: &WaitOptions, f: F) -> Result<T, E>where
F: FnMut() -> R,
R: Future<Output = WaitStatus<T, E>>,
E: Display,
Error: Into<E>,
Expand description
Call f
repeatedly, wait for it to return WaitStatus::Finished
, an error,
or a timeout. Honors WaitOptions
.
use bigml::wait::{wait, WaitOptions, WaitStatus};
use anyhow::Error;
let value = wait::<_, anyhow::Error, _, _>(&WaitOptions::default(), || {
async { WaitStatus::Finished("my value") }
}).await?;
assert_eq!(value, "my value");
If you return Ok(WaitStatus::Waiting)
instead, this function will wait
some number of seconds, and then try again.