Skip to main content

Waits

Enum Waits 

Source
pub enum Waits {
    Single(Wait),
    Or(Box<(Waits, Waits)>),
    And(Box<(Waits, Waits)>),
}
Expand description

Handles waiting for one or more Waits.

Variants§

§

Single(Wait)

§

Or(Box<(Waits, Waits)>)

§

And(Box<(Waits, Waits)>)

Implementations§

Source§

impl Waits

Source

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();
Source

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
Hide additional 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§

Source§

impl BitAnd for Waits

Source§

type Output = Waits

The resulting type after applying the & operator.
Source§

fn bitand(self, other: Waits) -> Self

Performs the & operation. Read more
Source§

impl BitAnd<Wait> for Waits

Source§

type Output = Waits

The resulting type after applying the & operator.
Source§

fn bitand(self, other: Wait) -> Self

Performs the & operation. Read more
Source§

impl BitAnd<Waits> for Wait

Source§

type Output = Waits

The resulting type after applying the & operator.
Source§

fn bitand(self, other: Waits) -> Self::Output

Performs the & operation. Read more
Source§

impl BitOr for Waits

Source§

type Output = Waits

The resulting type after applying the | operator.
Source§

fn bitor(self, other: Waits) -> Self

Performs the | operation. Read more
Source§

impl BitOr<Wait> for Waits

Source§

type Output = Waits

The resulting type after applying the | operator.
Source§

fn bitor(self, other: Wait) -> Self

Performs the | operation. Read more
Source§

impl BitOr<Waits> for Wait

Source§

type Output = Waits

The resulting type after applying the | operator.
Source§

fn bitor(self, other: Waits) -> Self::Output

Performs the | operation. Read more
Source§

impl From<Wait> for Waits

Source§

fn from(w: Wait) -> Self

Converts to this type from the input type.
Source§

impl Not for Waits

Source§

type Output = Waits

The resulting type after applying the ! operator.
Source§

fn not(self) -> Self::Output

Performs the unary ! operation. Read more

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> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.