我正在学习akka流,并在代码中遇到Keep.left和Keep.right:
I am learning akka stream and encounter Keep.left and Keep.right in the code:
implicit val system = ActorSystem("KafkaProducer") implicit val materializer = ActorMaterializer() val source = Source(List("a", "b", "c")) val sink = Sink.fold[String, String]("")(_ + _) val runnable: RunnableGraph[Future[String]] = source.toMat(sink)(Keep.right) val result: Future[String] = runnable.run()这里的Keep.right是什么意思?
What does here Keep.right mean?
推荐答案每个流处理阶段都可以产生一个物化值,可以使用viaMat或toMat(与via()或to()相对,分别).在代码段中,使用source.toMat(sink)表示您有兴趣捕获源和接收器的物化值,而Keep.right保留物化值的右侧(即接收器). Keep.left将物化值保留在左侧(即源),而Keep.both将允许您将两者都保留.
Every stream processing stage can produce a materialized value which can be captured using viaMat or toMat (as opposed to via() or to(), respectively). In your code snippet, the using of source.toMat(sink) indicates that you're interested in capturing the materialized value of the source and sink and Keep.right keeps the right side (i.e. sink) of the materialized value. Keep.left would keep the materialized value on the left side (i.e. source), and Keep.both would allow you to keep both.
Akka Streams文档.
更多推荐
Keep in akka stream是什么意思?
发布评论