【发布时间】:2019-07-09 15:06:21
【问题描述】:
我想使用带有两个不同接收器的Source。
简化示例:
val source = Source(1 to 20)
val addSink = Sink.fold[Int, Int](0)(_ + _)
val subtractSink = Sink.fold[Int, Int](0)(_ - _)
val graph = GraphDSL.create() { implicit builder =>
import GraphDSL.Implicits._
val bcast = builder.add(Broadcast[Int](2))
source ~> bcast.in
bcast.out(0) ~> addSink
bcast.out(1) ~> subtrackSink
ClosedShape
}
RunnableGraph.fromGraph(graph).run()
val result: Future[Int] = ???
我需要能够检索addSink 的结果。 RunnableGraph.fromGraph(graph).run() 给我NotUsed,
但我想得到一个Int(第一次折叠的结果Sink)。有可能吗?
【问题讨论】:
标签: scala akka akka-stream