I am using play framework to implement a REST API service.
In one function I am using a java async library to talk to another service and it returns a
java.util.concurrent.Future<T>
that I map (using Guava Futures.transform(~)
) into a java.util.concurrent.Future<play.mvc.Result>
.
Now, how do I make it a play.libs.F.Promise<Result>
so that I can make an AsyncResult
?
I found play.libs.Akka.asPromise(scala.concurrent.Future<T> future)
but I cannot find a way (in Java) to get a scala future from a java one.
EDIT TEMPORARY SOLUTION: Here is what I am using right now:
Future<T> future = asyncGetTheFuture();
Promise<T> promise = Akka.future(new JFutureToPromise<T>(tempFuture));
with
class JFutureToPromise<T> implements Callable<T> {
final Future<T> future;
final long time;
final TimeUnit unit;
private JFutureToPromise(Future<T> future, long time, TimeUnit unit) {
this.future = future;
this.time = time;
this.unit = unit;
}
private JFutureToPromise(Future<T> future) {
this(future, 10L, TimeUnit.SECONDS);
}
@Override
public T call() throws Exception {
return future.get(time, unit);
}
}