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

tech.ydb.core.utils.FutureTools Maven / Gradle / Ivy

There is a newer version: 2.3.0
Show newest version
package tech.ydb.core.utils;

import java.util.concurrent.CompletableFuture;
import java.util.concurrent.CompletionException;

/**
 *
 * @author Aleksandr Gorshenin
 */
public class FutureTools {
    private FutureTools() { }

    public static Throwable unwrapCompletionException(Throwable throwable) {
        Throwable cause = throwable;
        while (cause instanceof CompletionException && cause.getCause() != null) {
            cause = cause.getCause();
        }
        return cause;
    }

    public static  CompletableFuture failedFuture(Throwable t) {
        CompletableFuture f = new CompletableFuture<>();
        f.completeExceptionally(t);
        return f;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy