Rust tokio alternative to fold and map to run a function concurrently with different inputs

Solution 1:

IIUC what you want, you can use tokio::spawn to launch your tasks in the background and futures::join_all to wait until they have all completed. E.g. something like this (untested):

async fn run(input: &str) -> Vec<String> {
    vec![String::from(input), String::from(input)]
}

async fn main() {
    let input = vec!["1","2","3","4","5","6","7","8"];

    let handles = input.iter().map (|domain| {
        tokio::spawn (async move { run (domain).await })
    });

    let results = futures::join_all (handles).await;
}