org.apache.thrift.async.AsyncMethodFutureAdapter Maven / Gradle / Ivy
The newest version!
package org.apache.thrift.async;
import java.util.concurrent.CompletableFuture;
/**
* A simple adapter that bridges {@link AsyncMethodCallback} with {@link
* CompletableFuture}-returning style clients. Compiler generated code will invoke this adapter to
* implement {@code FutureClient}s.
*
* @param return type (can be {@link Void}).
*/
public final class AsyncMethodFutureAdapter implements AsyncMethodCallback {
private AsyncMethodFutureAdapter() {}
public static AsyncMethodFutureAdapter create() {
return new AsyncMethodFutureAdapter<>();
}
private final CompletableFuture future = new CompletableFuture<>();
public CompletableFuture getFuture() {
return future;
}
@Override
public void onComplete(T response) {
future.complete(response);
}
@Override
public void onError(Exception exception) {
future.completeExceptionally(exception);
}
}