org.apache.thrift.async.AsyncMethodFutureAdapter Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of libthrift Show documentation
Show all versions of libthrift Show documentation
Thrift is a software framework for scalable cross-language services development.
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);
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy