等待MergeHub完成

时间:2019-05-06 14:48:09

标签: scala akka-stream

我如何等待通过MergeHub合并的单个源的完成和所有流的完成? MergeHub返回Sink[T, NotUsed],迫不及待:

  implicit val system: ActorSystem = ActorSystem("my-system")
  implicit val mat: ActorMaterializer = ActorMaterializer()
  implicit val ec: ExecutionContext = system.dispatcher

  val src = Source.tick(1 second, 1 second, "message")
      .zipWith(Source(1 to 15))((a, b) => s"$a-$b")

  val printer = Sink.foreach[String](s => println(s))

  val sink = MergeHub.source[String].to(printer).run()

  val graph1: Future[Done] = src.runWith(printer) // Can be waited on

  val graph2: NotUsed = src.runWith(sink) // Cannot be waited on apparently

0 个答案:

没有答案