Keep in akka stream是什么意思? [英] What does Keep in akka stream mean?

查看:134
本文介绍了Keep in akka stream是什么意思?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在学习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?

推荐答案

每个流处理阶段都可以产生一个物化值,可以使用viaMattoMat(与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.

查看全文

登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆