Skip to content
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

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

justin1dennison
Copy link

No description provided.

#[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);

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.

/// This `struct` is created by the [`skip`] method on [`ParallelStream`]. See its
/// documentation for more.
///
/// [`skip`]: trait.ParallelStream.html#method.take

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.

@justin1dennison
Copy link
Author

justin1dennison commented Mar 24, 2020

I don't know if I am way off base with this implementation. I am having the following issue:


--> src/par_stream/skip.rs:42:23
   |
42 |         Skip { limit, receiver }
   |                       ^^^^^^^^ expected type parameter `T`, found associated type
   |
   = note: expected struct `async_std::sync::channel::Receiver<T>`
              found struct `async_std::sync::channel::Receiver<<S as par_stream::ParallelStream>::Item>`
   = note: you might be missing a type parameter or trait bound

Comment on lines +25 to +47
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;

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants