2

在 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);
4

1 回答 1

1

您需要将其包装Future<Result>在 aPromise<Result>中以在 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);
}
于 2013-12-18T23:21:06.363 回答