pub enum Waits {
Single(Wait),
Or(Box<(Waits, Waits)>),
And(Box<(Waits, Waits)>),
}Expand description
Handles waiting for one or more Waits.
Variants§
Implementations§
Source§impl Waits
impl Waits
Sourcepub fn condition_met(&self) -> bool
pub fn condition_met(&self) -> bool
Checks whether this condition - comprising all constituent Waits - is satisfied.
This is non-blocking, but depending on the conditions that comprise it, it may have some associated delay (eg, an HTTP GET incurs TCP and possibly TLS handshake latency).
Short-circuit functionality may also affect the delay. For example:
use waitforit::Wait;
let a = Wait::new_file_exists("foo.txt");
let b = Wait::new_tcp_connect("extremely_slow_host:80");
let ab = (a.clone() | b.clone()).condition_met();
let ba = (b | a).condition_met();Sourcepub fn wait(&self, interval: Duration)
pub fn wait(&self, interval: Duration)
Wait for the completion of this condition. This will block the thread.
Examples found in repository?
examples/negation.rs (line 16)
4fn main() {
5 let filename = "my_dataset.json";
6
7 // assume that our file exists
8 assert!(std::path::Path::new(filename).exists());
9
10 let first_10sec = !Wait::new_elapsed_from_duration(Duration::from_secs(10));
11 let file_updated = Wait::new_file_update(filename);
12 let file_not_exists = !Wait::new_file_exists(filename);
13
14 // either we update the file in the first 10 sec or we wait for it to be deleted
15 let w = (first_10sec & file_updated) | file_not_exists;
16 w.wait(Duration::from_secs(1));
17}More examples
examples/multiples.rs (line 18)
4fn main() {
5 // Wait for foo.txt to exist
6 let foo_exists = Wait::new_file_exists("foo.txt");
7
8 // And for foo.txt to stop being updated (considering it done if it's not been updated in at least 10sec).
9 let foo_done = !Wait::new_file_update_since("foo.txt", Duration::from_secs(10));
10
11 // Require these two conditions together (in order):
12 let foo = foo_exists & foo_done;
13
14 // No more than 30 seconds of elapsed time:
15 let bar = Wait::new_elapsed_from_duration(Duration::from_secs(30));
16
17 // Block until either foo or bar has completed, checking them every 1 second
18 (foo | bar).wait(Duration::from_secs(1));
19}examples/negation2.rs (line 16)
9fn main() {
10 let ten_sec = Wait::new_elapsed_from_duration(Duration::from_secs(10));
11 let lockfile = !Wait::new_file_exists("something.lock");
12
13 // wait until ten seconds has passed and the lockfile is gone
14 let w = ten_sec & lockfile;
15 let start = std::time::Instant::now();
16 w.wait(CHECK_DURATION);
17 println!("Step 1 complete after {:?}", start.elapsed());
18
19 // w is (ten seconds has passed) and (not(lockfile exists))
20 // not(w) is not((ten seconds has passed) and (not(lockfile exists)))
21 // -> (not(ten seconds has passed) or (lockfile exists))
22 let ten_sec = Wait::new_elapsed_from_duration(Duration::from_secs(10));
23 let lockfile = !Wait::new_file_exists("something.lock");
24 let w = ten_sec & lockfile;
25 let not_w = !w;
26 let start = std::time::Instant::now();
27 not_w.wait(CHECK_DURATION);
28 println!("Step 2 complete after {:?}", start.elapsed());
29}Trait Implementations§
Auto Trait Implementations§
impl !Freeze for Waits
impl !RefUnwindSafe for Waits
impl !Sync for Waits
impl Send for Waits
impl Unpin for Waits
impl UnsafeUnpin for Waits
impl UnwindSafe for Waits
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more