waitforit 0.1.0

A library to aid in synchronously waiting for some condition to be met.
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
use std::time::Duration;
use waitforit::Wait;

fn main() {
    let filename = "my_dataset.json";

    // assume that our file exists
    assert!(std::path::Path::new(filename).exists());

    let first_10sec = !Wait::new_elapsed_from_duration(Duration::from_secs(10));
    let file_updated = Wait::new_file_update(filename);
    let file_not_exists = !Wait::new_file_exists(filename);

    // either we update the file in the first 10 sec or we wait for it to be deleted
    let w = (first_10sec & file_updated) | file_not_exists;
    w.wait(Duration::from_secs(1));
}