Scala Akka Stream:如何通过Seq

时间:2015-09-10 07:17:46

标签: scala akka akka-stream reactive-streams

我试图在Future中包含一些阻止调用。返回类型为Seq[User],其中Usercase class。以下内容无法编辑各种重载版本的投诉。有什么建议?我试过几乎所有的变化都是Source.apply而没有任何运气。

// All I want is Seq[User] => Future[Seq[User]]

def findByFirstName(firstName: String) = {
  val users: Seq[User] = userRepository.findByFirstName(firstName)

  val sink = Sink.fold[User, User](null)((_, elem) => elem)

  val src = Source(users) // doesn't compile

  src.runWith(sink)
}

1 个答案:

答案 0 :(得分:2)

如果你只需要Future [Seq [Users]]不要使用akka流但是 futures

import scala.concurrent._
import ExecutionContext.Implicits.global
val session = socialNetwork.createSessionFor("user", credentials)
val f: Future[List[Friend]] = Future {
  session.getFriends()
}