From 3a5952652363e6507efe98216b3cce31ec8101ef Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=C3=A9o=20Gaspard?= Date: Fri, 31 Aug 2018 22:26:41 +0900 Subject: [PATCH] Document that timeout-ed futures will be polled at least once (#603) tokio-util: document behavior of `StreamExt::timeout` when timeout = 0 --- src/util/future.rs | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/util/future.rs b/src/util/future.rs index 27098e6b1..92097ad9e 100644 --- a/src/util/future.rs +++ b/src/util/future.rs @@ -31,6 +31,9 @@ pub trait FutureExt: Future { /// If the future completes before `timeout` then the future will resolve /// with that item. Otherwise the future will resolve to an error. /// + /// The future is guaranteed to be polled at least once, even if `timeout` + /// is set to zero. + /// /// # Examples /// /// ``` @@ -69,3 +72,16 @@ pub trait FutureExt: Future { } impl FutureExt for T where T: Future {} + +#[cfg(test)] +mod test { + use super::*; + use prelude::future; + + #[test] + fn timeout_polls_at_least_once() { + let base_future = future::result::<(), ()>(Ok(())); + let timeouted_future = base_future.timeout(Duration::new(0, 0)); + assert!(timeouted_future.wait().is_ok()); + } +}