方法1:
Promise<Integer> promiseOfInt = Promise.promise(() -> intensiveComputation());
Note: It’s important to understand which thread code runs on which promises. Here, the intensive computation will just be run on another thread.
方法2:
public static Result index() {
Promise<Integer> promiseOfInt = Akka.future(
new Callable<Integer>() {
public Integer call() {
intensiveComputation();
}
}
);
async(
promiseOfInt.map(
new Function<Integer,Result>() {
public Result apply(Integer i) {
return ok("Got result: " + i);
}
}
)
);
}
map 与 flatmap 请看haskell 的介绍,几本一个东西。
方法3:
https://www.playframework.com/documentation/2.4.x/JavaAkka
https://www.playframework.com/documentation/2.3.x/JavaAkka
https://www.playframework.com/documentation/2.0/JavaAkka