我正在斯卡拉的期货周围慢慢地包裹着我的大脑,并有一点点的蛋糕正在尝试解开。在斯卡拉期货迷路
具体使用案例是 sangria-graphql + akka。我已经偷了他们的演示代码,它看起来像这样
Future.fromTry(Try(
friendIds map (id => CharacterRepo.humans.find(_.id == id) orElse CharacterRepo.droids.find(_.id == id))))
,并加入我自己修改它。他们确实在内存中查找,而我的要求的另一位演员的东西:
Future.fromTry(Try(
accountIds match {
case h :: _ =>
val f = sender ? TargetedMessage(h)
val resp = Await.result(f, timeout.duration).asInstanceOf[TargetedMessage]
marshallAccount(resp.body)
case _ => throw new Exception("Not found")
}
))
这里的相关部分是我挑的第一个元素在列表中,将其发送到ActorRef
,我得到了其他地方,等待结果。这工作。我今天准备这样做,但是,是不是还得等待结果在这里,但回到整个事情的Future
Future.fromTry(Try(
accountIds match {
case h :: _ =>
sender ? TargetedMessage(h) map {
case resp:TargetedMessage => marshallAccount(resp.body)
}
case _ => throw new Exception("Not found")
}
))
这是行不通的。当这个被消耗的,而不是Account
型(功能marshallAccount
返回类型,它的类型作出承诺。如果我理解正确的话,那是因为,而不是具有Future[Account]
返回类型,这有一个类型的Future[Future[Account]]
如何拉平这个