orphanage 0.5.6

Random collection of stuff that is still searching for a home.
Documentation
//! tokio extensions.

/// If a timeout has been specified, sleep until then.
///
/// Otherwise wait forever.
///
/// Can be used to timeout select loops.
pub async fn sleep_until_if_some(at: Option<tokio::time::Instant>) {
  if let Some(to) = at {
    if tokio::time::Instant::now() >= to {
      return;
    }
    tokio::time::sleep_until(to).await;
  } else {
    let () = std::future::pending().await;
  }
}

pub async fn sleep_for_if_some(dur: Option<std::time::Duration>) {
  if let Some(dur) = dur {
    tokio::time::sleep(dur).await;
  } else {
    let () = std::future::pending().await;
  }
}

// vim: set ft=rust et sw=2 ts=2 sts=2 cinoptions=2 tw=79 :