Skip to content

Commit 95a3e53

Browse files
committed
Only use the Option of the future to decide to construct a new one
1 parent 02b261d commit 95a3e53

File tree

1 file changed

+9
-11
lines changed

1 file changed

+9
-11
lines changed

src/stream/successor.rs

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,9 @@ where Fut: Future<Output=T>
3939
/// });
4040
///
4141
/// pin_utils::pin_mut!(s);
42-
/// assert_eq!(s.next().await, Some(1));
43-
/// assert_eq!(s.next().await, Some(2));
44-
/// assert_eq!(s.next().await, Some(3));
42+
/// assert_eq!(s.next().await, Some(23));
43+
/// assert_eq!(s.next().await, Some(24));
44+
/// assert_eq!(s.next().await, Some(25));
4545
/// #
4646
/// # }) }
4747
///
@@ -83,20 +83,18 @@ where
8383

8484
fn poll_next(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Option<Self::Item>> {
8585
match &self.future {
86-
Some(_) => {
87-
let next = futures_core::ready!(self.as_mut().future().as_pin_mut().unwrap().poll(cx));
88-
self.as_mut().future().set(None);
89-
90-
Poll::Ready(Some(next))
91-
},
9286
None => {
9387
let x = self.next;
9488
let fut = (self.as_mut().successor())(x);
9589
self.as_mut().future().set(Some(fut));
96-
// Probably can poll the value here?
97-
Poll::Pending
9890
}
91+
_ => {},
9992
}
93+
94+
let next = futures_core::ready!(self.as_mut().future().as_pin_mut().unwrap().poll(cx));
95+
*self.as_mut().next() = next;
96+
self.as_mut().future().set(None);
97+
Poll::Ready(Some(next))
10098
}
10199
}
102100

0 commit comments

Comments
 (0)