8

如何创建一个Promise<Result>in Play 2.0 框架 - Java

我看到这个链接http://www.playframework.org/documentation/2.0.4/JavaAsync。它不包含那么多细节。除了参考我之外,你知道任何教程吗?请。

4

4 回答 4

8

这是在 Play 2.2 中创建 Promise 的新方法

Promise<Boolean> myPromise = Promise.promise(new Function0<Boolean>() {
    public Boolean apply() throws Throwable {
        // TODO - Add Implementation here.
        return Boolean.TRUE;
    }

});
于 2013-11-25T04:25:42.290 回答
7

James Roper(Play 框架开发人员)有一个在 Play 中与 Java 一起使用 Promise 的好例子: https://github.com/jroper/play-promise-presentation/blob/master/src/main/java/controllers/Application。爪哇

于 2012-10-03T17:59:21.107 回答
4

您提到的文档中所述,请使用Akka.future

Promise<Result> promiseOfResult = Akka.future(
    new Callable<Result>() {
      public Result call() {
        return ok("This is a promise result !");
      }
    }
  );
于 2012-10-03T12:52:17.710 回答
1
public F.Promise<Result> asyncFoo() {

          F.Promise<Integer> promise = F.Promise.promise(() -> longRunningCalculation());

          return promise.map((Integer i) -> ok("The calculation result is: " + i));

}

https://www.typesafe.com/blog/play-framework-with-java-8

于 2015-10-26T14:16:44.840 回答