Related question; what's the advantage of:
...
I was wondering if there was a good reason to have two separate
promises, because the documentation states that "to create a
Promise<Result> we need another promise first".
So the correct answer is that there is no reason to create a
Promise<Integer> in this case; it's just done to show how to use
Promise.map, which is equivalent to:
public static Result index() {
final Promise<Integer> promiseOfInt = ...
return async(Akka.future(new Callable<Result>() {
public Result call() {
return ok("Got result: " + promiseOfInt.get());
}
});
}
Correct?
Also, I'm still looking for the best way to make use of a
java.util.concurrent.Future. Is there any reason to wrap it in a
Promise<Integer> (how?) that is then mapped to a Promise<Result>,
rather than simply doing the following?
public static Result index() {
final Future<Integer> intFuture = ...
return async(Akka.future(new Callable<Result>() {
public Result call() {
return ok("Got result: " + intFuture.get());
}
});
}
So the correct answer is that there is no reason to create aPromise<Integer> in this case; it's just done to show how to use
Promise.map, which is equivalent to:
public static Result index() {
final Promise<Integer> promiseOfInt = ...
return async(Akka.future(new Callable<Result>() {return ok("Got result: " + promiseOfInt.get());
public Result call() {
}
});
}
Correct?
Also, I'm still looking for the best way to make use of a
java.util.concurrent.Future. Is there any reason to wrap it in a
Promise<Integer> (how?) that is then mapped to a Promise<Result>,
rather than simply doing the following?
It hadn't occurred to me that the goal here isn't just to avoid
blocking on the request handling thread, but to avoid blocking any
thread. Seen in that light, this now makes sense :-)
> That's a tough one. If the Future is actually one of Netty's
> ListenableFuture or something equivalent then it is easy [...]
Some of the Future instances I'm dealing with happen to have an
addListener() method. But how do I adapt those Futures to a Promise?
The code looks like so:
client.prepare().addListener(new ActionListener<String>() {
@Override
public void onResponse(String id) {
}
@Override
public void onFailure(Throwable t) {
}
});
Problem #1: The only way I can find to create a Promise using Play's
Java API is via Akka.future(callable).
The code looks like so:
client.prepare().addListener(new ActionListener<String>() {
@Override
public void onResponse(String id) {
}
@Override
public void onFailure(Throwable t) {
}
});
Problem #1: The only way I can find to create a Promise using Play's
Java API is via Akka.future(callable).
Thanks; here's how I got it to work:
final Promise<String> promise = new
DefaultPromise<String>(Akka.system().dispatcher());