Keep in akka stream是什么意思?

编程入门 行业动态 更新时间:2024-10-27 10:28:23
本文介绍了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?

推荐答案

每个流处理阶段都可以产生一个物化值,可以使用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是什么意思?

本文发布于:2023-11-25 08:04:07,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1628965.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:akka   stream

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!