wait_on/
lib.rs

1//! Wait-On library to wait on the availability of resources
2//! such as Files, HTTP Servers, Ports & Sockets
3
4pub mod resource;
5pub mod task;
6
7use std::time::Duration;
8
9use anyhow::Result;
10
11const SECONDS_IN_HOUR: u64 = 3600;
12
13/// Options available for waiting on a [`Waitable`].
14#[derive(Clone, Debug)]
15pub struct WaitOptions {
16    /// Timeout in milliseconds for the wait operation.
17    pub timeout: Duration,
18}
19
20impl Default for WaitOptions {
21    fn default() -> Self {
22        Self {
23            timeout: Duration::from_secs(SECONDS_IN_HOUR),
24        }
25    }
26}
27
28/// A [`Waitable`] is an resource that can be waited on.
29///
30/// Every [`Resource`] must implement this trait.
31///
32/// # Should not be implemented by the user
33///
34/// This trait should not be implemented by the user, instead, it should be
35/// implemented by the [`Resource`] enum variants in the `lib` scope.
36#[allow(async_fn_in_trait)]
37pub trait Waitable {
38    async fn wait(&self, options: &WaitOptions) -> Result<()>;
39}