All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.bdeploy.common.util.FutureHelper Maven / Gradle / Ivy

Go to download

Public API including dependencies, ready to be used for integrations and plugins.

There is a newer version: 7.3.6
Show newest version
package io.bdeploy.common.util;

import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.concurrent.Future;

/**
 * Helper to aid in working with {@link Future}s
 */
public class FutureHelper {

    private FutureHelper() {
    }

    public static void awaitAll(Collection> futures) {
        List exceptions = new ArrayList<>();

        futures.forEach(t -> {
            try {
                t.get();
            } catch (InterruptedException ie) {
                Thread.currentThread().interrupt();
                exceptions.add(ie);
            } catch (Exception e) {
                exceptions.add(e);
            }
        });

        if (!exceptions.isEmpty()) {
            IllegalStateException ise = new IllegalStateException("Asynchronous operation(s) failed");
            exceptions.forEach(ise::addSuppressed);
            throw ise;
        }
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy