Skip to content

Commit

Permalink
CI test
Browse files Browse the repository at this point in the history
  • Loading branch information
evanrittenhouse committed Jan 8, 2024
1 parent 84c5674 commit e7620df
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions tokio-util/src/time/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,33 @@ pub mod delay_queue;

#[doc(inline)]
pub use delay_queue::DelayQueue;
use futures_core::Future;
use tokio::time::Timeout;

/// A trait which contains a variety of conevenient adapters and utilities for `Future`s.
pub trait FutureExt: Future + Sized {
/// A wrapper around [`tokio::time::timeout`], with the advantage that it is easier to write
/// fluent call chains.
///
/// # Examples
///
/// ```rust
/// use tokio::{sync::oneshot, time::Duration};
/// use tokio_util::time::FutureExt;
///
/// # async fn dox() {
/// let (tx, rx) = oneshot::channel::<()>();
///
/// let res = rx.timeout(Duration::from_millis(10)).await;
/// assert!(res.is_err());
/// # }
/// ```
fn timeout(self, timeout: Duration) -> Timeout<Self> {
tokio::time::timeout(timeout, self)
}
}

impl<T: Future + Sized> FutureExt for T {}

// ===== Internal utils =====

Expand Down

0 comments on commit e7620df

Please sign in to comment.