-
Notifications
You must be signed in to change notification settings - Fork 16
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Added skip and Skip struct to parallel stream. #12
base: master
Are you sure you want to change the base?
Conversation
src/par_stream/skip.rs
Outdated
#[async_std::test] | ||
async fn smoke() { | ||
use async_std::prelude::*; | ||
let s = async_std::stream::from_iter(vec![1, 2, 3, 4, 5, 6]).skip(3); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Your test is calling async_std::stream::Stream
, not ParallelStream::skip
.
src/par_stream/skip.rs
Outdated
/// This `struct` is created by the [`skip`] method on [`ParallelStream`]. See its | ||
/// documentation for more. | ||
/// | ||
/// [`skip`]: trait.ParallelStream.html#method.take |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this should be trait.ParallelStream.html#method.skip
.
I don't know if I am way off base with this implementation. I am having the following issue:
|
impl<T: Send + 'static> Skip<T> { | ||
pub(super) fn new<S>(mut stream: S, mut skipped: usize) -> Self | ||
where | ||
S: ParallelStream | ||
{ | ||
let limit = stream.get_limit(); | ||
let (sender, receiver) = sync::channel(1); | ||
task::spawn(async move { | ||
while let Some(val) = stream.next().await { | ||
if skipped == 0 { | ||
sender.send(val).await | ||
} else { | ||
skipped -= 1; | ||
} | ||
} | ||
}); | ||
|
||
Skip { limit, receiver } | ||
} | ||
} | ||
|
||
impl<T: Send + 'static> ParallelStream for Skip<T> { | ||
type Item = T; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You could use the same approach as Take
:
impl<S: ParallelStream> Skip<S> {
...
}
impl<S: ParallelStream> ParallelStream for Skip<S> {
type Item = S::Item;
...
}
Otherwise, the compiler will think you're trying to transform a ParallelStream<Item = X>
into a ParallelStream<Item = T>
and it will not be able to figure out what T
is.
No description provided.