forked from mirror/async-std
Only use the Option of the future to decide to construct a new one
This commit is contained in:
parent
02b261de10
commit
95a3e53fcd
1 changed files with 9 additions and 11 deletions
|
@ -39,9 +39,9 @@ where Fut: Future<Output=T>
|
|||
/// });
|
||||
///
|
||||
/// 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<Option<Self::Item>> {
|
||||
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))
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue