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

StreamExt::collect does not preserve Send #639

Closed
rmanoka opened this issue Dec 21, 2019 · 2 comments
Closed

StreamExt::collect does not preserve Send #639

rmanoka opened this issue Dec 21, 2019 · 2 comments

Comments

@rmanoka
Copy link

rmanoka commented Dec 21, 2019

Hi,

The StreamExt::collect in this crate (with unstable feature-flag) converts a Send stream into future that is not Send anymore. On the other hand, futures::StreamExt seems to preserve this auto trait. This is not a mission-critical issue, but thought I'll bring it to your attention anyway.

Test code to reproduce this, that yields a compilation error:

#[async_std::test]
async fn test_send() {
    fn test_send_trait<T: Send>(_: &T) {}

    let stream = futures::stream::pending::<()>();
    test_send_trait(&stream);

    use async_std::prelude::StreamExt;
    let fut = stream.collect::<Vec<_>>();

    // This line triggers a compilation error
    test_send_trait(&fut);
}

Tested on 1.4.0

@yoshuawuyts
Copy link
Contributor

@rmanoka hi, thanks for raising this! Heh yeah that's no good; we should fix that.

@yoshuawuyts
Copy link
Contributor

Okay I'm able to reproduce this. A concrete example of the issue above is:

use async_std::prelude::*;
use async_std::io;
use async_std::task;

#[test]
fn test_send() -> io::Result<()> {
    task::block_on(async {
        fn test_send_trait<T: Send>(_: &T) {}

        let stream = futures::stream::pending::<()>();
        test_send_trait(&stream);


        task::spawn(async move {
            let _output = stream.collect::<Vec<_>>().await; // compile error here
        });
        Ok(())
    })
}

A possible solution here is to add Send back to the trait bounds of the Future, which I believe we originally had. Trying that out now.

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

No branches or pull requests

2 participants