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

org.zalando.riptide.CompletableFutures Maven / Gradle / Ivy

The newest version!
package org.zalando.riptide;

import org.apiguardian.api.API;

import java.util.concurrent.CompletableFuture;
import java.util.function.BiConsumer;

import static java.util.Objects.nonNull;
import static org.apiguardian.api.API.Status.EXPERIMENTAL;

@API(status = EXPERIMENTAL)
public final class CompletableFutures {

    private CompletableFutures() {

    }

    public static  CompletableFuture exceptionallyCompletedFuture(final Throwable throwable) {
        final CompletableFuture future = new CompletableFuture<>();
        future.completeExceptionally(throwable);
        return future;
    }

    public static  BiConsumer forwardTo(final CompletableFuture future) {
        return (response, throwable) -> {
            if (nonNull(response)) {
                future.complete(response);
            }
            if (nonNull(throwable)) {
                future.completeExceptionally(throwable);
            }
        };
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy