From 95a3e53fcdcab2d0610e54aa9520c152a11a1ceb Mon Sep 17 00:00:00 2001 From: Felipe Sere Date: Fri, 18 Oct 2019 09:00:38 +0200 Subject: [PATCH] Only use the Option of the future to decide to construct a new one --- src/stream/successor.rs | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/src/stream/successor.rs b/src/stream/successor.rs index 434ef97..3ddeef4 100644 --- a/src/stream/successor.rs +++ b/src/stream/successor.rs @@ -39,9 +39,9 @@ where Fut: Future /// }); /// /// pin_utils::pin_mut!(s); -/// assert_eq!(s.next().await, Some(1)); -/// assert_eq!(s.next().await, Some(2)); -/// assert_eq!(s.next().await, Some(3)); +/// assert_eq!(s.next().await, Some(23)); +/// assert_eq!(s.next().await, Some(24)); +/// assert_eq!(s.next().await, Some(25)); /// # /// # }) } /// @@ -83,20 +83,18 @@ where fn poll_next(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll> { match &self.future { - Some(_) => { - let next = futures_core::ready!(self.as_mut().future().as_pin_mut().unwrap().poll(cx)); - self.as_mut().future().set(None); - - Poll::Ready(Some(next)) - }, None => { let x = self.next; let fut = (self.as_mut().successor())(x); self.as_mut().future().set(Some(fut)); - // Probably can poll the value here? - Poll::Pending } + _ => {}, } + + let next = futures_core::ready!(self.as_mut().future().as_pin_mut().unwrap().poll(cx)); + *self.as_mut().next() = next; + self.as_mut().future().set(None); + Poll::Ready(Some(next)) } }