How to create a Promise<Result> play2.0 framework - Java
12,598
Solution 1
James Roper (a Play Framework developer) has a good example for using Promise in Play with Java: https://github.com/jroper/play-promise-presentation/blob/master/src/main/java/controllers/Application.java
Solution 2
This is new way of creating Promise in Play 2.2
Promise<Boolean> myPromise = Promise.promise(new Function0<Boolean>() {
public Boolean apply() throws Throwable {
// TODO - Add Implementation here.
return Boolean.TRUE;
}
});
Solution 3
As explained in the doc that you mention, use an Akka.future
:
Promise<Result> promiseOfResult = Akka.future(
new Callable<Result>() {
public Result call() {
return ok("This is a promise result !");
}
}
);
Solution 4
public F.Promise<Result> asyncFoo() {
F.Promise<Integer> promise = F.Promise.promise(() -> longRunningCalculation());
return promise.map((Integer i) -> ok("The calculation result is: " + i));
}
Comments
-
bdeveloper01 almost 2 years
How to create a
Promise<Result>
in Play 2.0 framework - JavaI see this link http://www.playframework.org/documentation/2.0.4/JavaAsync. it doesn't contain that much details. do you known any tutorial than refer to me. pls.