From bcaac2b2e39915ae0eb7955937584a177598735b Mon Sep 17 00:00:00 2001 From: Avril Date: Mon, 12 Oct 2020 20:10:04 +0100 Subject: [PATCH] remove sender clone --- src/msg.rs | 30 ++++++++++++++++++++++++++++++ src/state.rs | 5 ++--- 2 files changed, 32 insertions(+), 3 deletions(-) diff --git a/src/msg.rs b/src/msg.rs index 1c474a3..5352efa 100644 --- a/src/msg.rs +++ b/src/msg.rs @@ -64,7 +64,37 @@ impl Initialiser rx, } } + + pub fn into_wait(self) -> impl Future> + 'static + { + let mut rx = self.rx; + async move { + if !*rx.borrow() { + while !rx.recv().await.ok_or_else(|| InitWaitError)? { + //tokio::task::yield_now().await; + } + Ok(()) + } else { + Ok(()) + } + } + } + pub fn clone_into_wait(&self) -> impl Future> + 'static + { + let mut rx = self.rx.clone(); + async move { + if !*rx.borrow() { + while !rx.recv().await.ok_or_else(|| InitWaitError)? { + //tokio::task::yield_now().await; + } + Ok(()) + } else { + Ok(()) + } + } + } + pub async fn wait(&mut self) -> Result<(), InitWaitError> { if !*self.rx.borrow() { diff --git a/src/state.rs b/src/state.rs index a8f5cee..971353e 100644 --- a/src/state.rs +++ b/src/state.rs @@ -60,9 +60,8 @@ impl State if self.has_shutdown() { return Err(ShutdownError); } - let mut begin = self.begin.clone(); - tokio::select!{ //fuck - Ok(()) = begin.wait() => Ok(()), + tokio::select! { + Ok(()) = self.begin.clone_into_wait() => Ok(()), _ = self.on_shutdown() => { debug!("on_init(): shutdown received"); Err(ShutdownError)