yoshuawuyts / futures-concurrency

Structured concurrency operations for async Rust
https://docs.rs/futures-concurrency
Apache License 2.0
400 stars 31 forks source link

no progress with concurrent streams and tokio #183

Closed yanns closed 5 months ago

yanns commented 5 months ago

When using the following code:

async fn say_hello(who: &str) -> Vec<String> {
    let input: Vec<_> = (1..=5).collect();
    let results = input
        .into_co_stream()
        .map(|i| hello(i, who))
        .collect()
        .await;

    results
}

async fn hello(i: i32, who: &str) -> String {
    println!("Job {i} started");
    tokio::time::sleep(std::time::Duration::from_secs(1)).await;
    let result = format!("Task {i}: Hello {who}");
    println!("Job {i} finished with result {result}");
    result
}

The program outputs:

Starting jobs...
Job 1 started
Job 2 started
Job 3 started
Job 4 started
Job 5 started
Job 5 finished with result Task 5: Hello world

and does not make any progress afterwards

yoshuawuyts commented 5 months ago

Thank you for reporting this! This seems like a likely duplicate of #182. I'm going to close this in favor of that.