forked from mirror/async-std
fix: stream::take_while (#485)
When the predicate is false, the stream should be ended.
This commit is contained in:
parent
d2d63348c7
commit
4a78f731b7
2 changed files with 9 additions and 6 deletions
|
@ -303,6 +303,7 @@ extension_trait! {
|
||||||
|
|
||||||
#
|
#
|
||||||
# }) }
|
# }) }
|
||||||
|
```
|
||||||
"#]
|
"#]
|
||||||
fn take_while<P>(self, predicate: P) -> TakeWhile<Self, P, Self::Item>
|
fn take_while<P>(self, predicate: P) -> TakeWhile<Self, P, Self::Item>
|
||||||
where
|
where
|
||||||
|
|
|
@ -45,10 +45,12 @@ where
|
||||||
let next = futures_core::ready!(this.stream.poll_next(cx));
|
let next = futures_core::ready!(this.stream.poll_next(cx));
|
||||||
|
|
||||||
match next {
|
match next {
|
||||||
Some(v) if (this.predicate)(&v) => Poll::Ready(Some(v)),
|
Some(v) => {
|
||||||
Some(_) => {
|
if (this.predicate)(&v) {
|
||||||
cx.waker().wake_by_ref();
|
Poll::Ready(Some(v))
|
||||||
Poll::Pending
|
} else {
|
||||||
|
Poll::Ready(None)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
None => Poll::Ready(None),
|
None => Poll::Ready(None),
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue