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

org.eclipse.edc.util.async.AsyncUtils Maven / Gradle / Ivy

There is a newer version: 0.9.1
Show newest version
/*
 *  Copyright (c) 2022 Amadeus
 *
 *  This program and the accompanying materials are made available under the
 *  terms of the Apache License, Version 2.0 which is available at
 *  https://www.apache.org/licenses/LICENSE-2.0
 *
 *  SPDX-License-Identifier: Apache-2.0
 *
 *  Contributors:
 *       Amadeus - Initial implementation
 *
 */

package org.eclipse.edc.util.async;

import java.util.List;
import java.util.concurrent.CompletableFuture;
import java.util.function.Function;
import java.util.stream.Collector;
import java.util.stream.Collectors;

public class AsyncUtils {

    private AsyncUtils() {
    }

    public static > Collector>> asyncAllOf() {
        Function, CompletableFuture>> finisher = list -> CompletableFuture
                .allOf(list.toArray(CompletableFuture[]::new))
                .thenApply(v -> list.stream().map(CompletableFuture::join).collect(Collectors.toList()));

        return Collectors.collectingAndThen(Collectors.toList(), finisher);
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy