org.zalando.riptide.CompletableFutures Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of riptide-core Show documentation
Show all versions of riptide-core Show documentation
Client side response routing
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