【问题标题】:Play 2.0 Pipe promise to another actor向另一个演员播放 2.0 管道承诺
【发布时间】:2012-06-18 06:08:40
【问题描述】:

在 Akka 中,您可以将未来传递给演员。在 Play 2.0 的承诺下怎么能做到?

http://doc.akka.io/docs/akka/current/scala/actors.html#Ask__Send-And-Receive-Future

final Future<Result> transformed = aggregate.map(new Mapper<Iterable<Object>, Result>() {
  public Result apply(Iterable<Object> coll) {
    final Iterator<Object> it = coll.iterator();
    final String s = (String) it.next();
    final int x = (Integer) it.next();
    return new Result(x, s);
  }
});

pipe(transformed).to(actorC);

【问题讨论】:

  • 你好,angelokh。你搞清楚了吗?

标签: playframework-2.0 akka


【解决方案1】:

您需要将 Future&lt;Result&gt; 包装在 Promise&lt;Result&gt; 中,以便在 Play 中的异步请求处理程序中使用它。这是一个例子:

public static F.Promise<Result> foo() {

    ActorRef fooActor = Akka.system().actorOf(Props.create(FooActor.class));

    Future<Object> response = ask(fooActor, "message", 5000);

    Future<Result> result = response.map(new Mapper<Object, Result>() {
        @Override
        public Result apply(Object message) {
            return ok("whatever");
        }
    }, HttpExecution.defaultContext());

    return F.Promise.wrap(result);
}

【讨论】:

    猜你喜欢
    • 2015-05-27
    • 1970-01-01
    • 2015-03-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多