如何创建Promise <result> play2.0框架 - Java </result>

时间:2012-10-03 12:31:31

标签: playframework playframework-2.0

如何在Play 2.0框架中创建Promise<Result> - Java

我看到此链接http://www.playframework.org/documentation/2.0.4/JavaAsync。它没有包含那么多细节。你知道任何教程而不是引用我吗? PLS。

4 个答案:

答案 0 :(得分: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;
    }

});

答案 1 :(得分:7)

James Roper(Play Framework开发人员)在Play with Java中使用Promise就是一个很好的例子: https://github.com/jroper/play-promise-presentation/blob/master/src/main/java/controllers/Application.java

答案 2 :(得分:4)

正如the doc that you mention中所述,使用Akka.future

Promise<Result> promiseOfResult = Akka.future(
    new Callable<Result>() {
      public Result call() {
        return ok("This is a promise result !");
      }
    }
  );

答案 3 :(得分: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