0

I can use shiplift to get a list of the running containers but I have found it very difficult to stop them. After much trial and error, it seems I can create a vector of futures and then join them all in order to create a single future to return. This joined future does not seem to be called and the containers are never stopped. Is there a better way to run all these futures and then return the result?

let docker = connection.clone();
docker
    .containers()
    .list(&Default::default())
    .map(move |list| {
        let mut futures = Vec::new();
        for container in list {
            let cont = connection.containers().get(&container.id);
            println!("Stopping {}", cont.id());
            futures.push(cont.stop(Some(std::time::Duration::from_secs(1))));
            // futures.push(connection.containers().get(&container.id).stop(None).map_err(|_| println!("error")));
        }
        join_all(futures)
    })
    .map(|_| println!("Stopped all"))
    .map_err(|e| eprintln!("Error: {}", e))
Shepmaster
  • 388,571
  • 95
  • 1,107
  • 1,366
user2327063
  • 126
  • 5
  • It's hard to answer your question because it doesn't include a [MRE]. We can't tell what crates (and their versions), types, traits, fields, etc. are present in the code. It would make it easier for us to help you if you try to reproduce your error on the [Rust Playground](https://play.rust-lang.org) if possible, otherwise in a brand new Cargo project, then [edit] your question to include the additional info. There are [Rust-specific MRE tips](//stackoverflow.com/tags/rust/info) you can use to reduce your original code for posting here. Thanks! – Shepmaster Oct 28 '19 at 17:47
  • It looks like your question might be answered by the answers of [How do I synchronously return a value calculated in an asynchronous Future in stable Rust?](https://stackoverflow.com/q/52521201/155423). If not, please **[edit]** your question to explain the differences. Otherwise, we can mark this question as already answered. – Shepmaster Oct 28 '19 at 17:49

0 Answers0