How to create a Promise<Result>
in Play 2.0 framework - Java
I 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.
How to create a Promise<Result>
in Play 2.0 framework - Java
I 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.
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
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;
}
});
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
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 !");
}
}
);
public F.Promise<Result> asyncFoo() {
F.Promise<Integer> promise = F.Promise.promise(() -> longRunningCalculation());
return promise.map((Integer i) -> ok("The calculation result is: " + i));
}
© 2022 - 2024 — McMap. All rights reserved.