Instantly share code, notes, and snippets.

What would you like to do?
CompletableFuture to F.Promise Adapter
The following adapter is inspired by mattiwintou adapter from Rx Observable to F.Promise
public F.Promise<Result> rankedPairs() {
CompletableFuture cf = ...
return RxFuture.toPromise(cf).map(Controller::ok);
import play.libs.F;
import java.util.concurrent.CompletableFuture;
public class RxFuture<T> {
private final CompletableFuture<T> cf;
public RxFuture(final CompletableFuture<T> cf) { = cf;
public static <E> F.Promise<E> toPromise(final CompletableFuture<E> obs) {
return new RxFuture(obs).adopt();
public F.Promise<T> adopt() {
F.RedeemablePromise<T> rPromise = F.RedeemablePromise.empty();
cf.whenCompleteAsync((res, err) -> {
if (err != null) {
} else {
return rPromise;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment