From cf7435ba30c74801f866dd9f1007d7f90d778c55 Mon Sep 17 00:00:00 2001 From: Carl Lerche Date: Fri, 9 Mar 2018 11:09:10 -0800 Subject: [PATCH] CurrentThread::turn should block on idle. (#212) This patch fixes a bug where `CurrentThread::turn` is expected to block even if the executor is idle. The `turn` API is the low level interface for callers to interact with the `Sleep` instance used by the `CurrentThread` instance. As such, a call to `turn` is expected to call `sleep` once if the executor did not perform any work. --- src/executor/current_thread/mod.rs | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/src/executor/current_thread/mod.rs b/src/executor/current_thread/mod.rs index e61fdd2ca..a5035d64c 100644 --- a/src/executor/current_thread/mod.rs +++ b/src/executor/current_thread/mod.rs @@ -353,7 +353,9 @@ impl CurrentThread

{ self.enter(&mut enter).run_timeout(duration) } - /// Perform a single iteration of the event loop + /// Perform a single iteration of the event loop. + /// + /// This function blocks the current thread even if the executor is idle. pub fn turn(&mut self, duration: Option) -> Result { @@ -462,15 +464,12 @@ impl<'a, P: Park> Entered<'a, P> { self.run_timeout2(Some(duration)) } - /// Perform a single iteration of the event loop + /// Perform a single iteration of the event loop. + /// + /// This function blocks the current thread even if the executor is idle. pub fn turn(&mut self, duration: Option) -> Result { - if self.executor.is_idle() { - // Nothing to do - return Ok(Turn(())); - } - if !self.tick() { let res = match duration { Some(duration) => self.executor.park.park_timeout(duration),