Improved the code with some minor changes

new-scheduler
razican 5 years ago
parent f6829859fe
commit 72ca2c1a24
No known key found for this signature in database
GPG Key ID: 76E895FB1EDE827C

@ -62,12 +62,11 @@ where
S: Stream<Item = I>, S: Stream<Item = I>,
{ {
match first.poll_next(cx) { match first.poll_next(cx) {
Poll::Ready(Some(item)) => Poll::Ready(Some(item)),
Poll::Ready(None) => second.poll_next(cx), Poll::Ready(None) => second.poll_next(cx),
Poll::Ready(item) => Poll::Ready(item),
Poll::Pending => match second.poll_next(cx) { Poll::Pending => match second.poll_next(cx) {
Poll::Ready(Some(item)) => Poll::Ready(Some(item)), Poll::Ready(None) | Poll::Pending => Poll::Pending,
Poll::Ready(None) => Poll::Pending, Poll::Ready(item) => Poll::Ready(item),
Poll::Pending => Poll::Pending,
}, },
} }
} }

@ -1663,18 +1663,14 @@ extension_trait! {
``` ```
# async_std::task::block_on(async { # async_std::task::block_on(async {
use async_std::prelude::*; use async_std::prelude::*;
use async_std::stream; use async_std::stream::{self, FromStream};
let a = stream::once(1u8); let a = stream::once(1u8);
let b = stream::once(2u8); let b = stream::once(2u8);
let c = stream::once(3u8); let c = stream::once(3u8);
let mut s = a.merge(b).merge(c); let s = a.merge(b).merge(c);
let mut lst = Vec::new(); let mut lst = Vec::from_stream(s).await;
while let Some(n) = s.next().await {
lst.push(n)
}
lst.sort_unstable(); lst.sort_unstable();
assert_eq!(&lst, &[1u8, 2u8, 3u8]); assert_eq!(&lst, &[1u8, 2u8, 3u8]);

Loading…
Cancel
Save