gpt4 book ai didi

scala - 在Akka Streams中,Sink.fold()处理是序列化的吗?

转载 作者:行者123 更新时间:2023-12-01 10:01:56 25 4
gpt4 key购买 nike

我开始使用 Akka 流;我正在尝试创建一个从 Web 服务读取数据然后将它们保存在 S3 中的流。我想知道,如果我使用 Sink.fold 方法(为了收集有关持久元素的信息)定义一个 Sink 用于持久化,那么发送到 sink 的元素是一个接一个地处理还是并行处理?

这是一个基本问题,但我无法在文档中找到明确的答案。

最佳答案

由于 Sink.fold 需要将前一个元素的结果与下一个元素组合,因此它必须是顺序的。

实际上,它更像是一个 Sink.foldLeft

换句话说,如果你有 a, b 作为元素,你用 f 折叠它们,你需要 acc = f(zero, a) 以便能够处理 f(acc, b)。因此,在 a 的处理完成之前,无法处理 b

来自api doc :

A Sink that will invoke the given function for every received element, giving it its previous output (or the given zero value) and the element as input. The returned java.util.concurrent.CompletionStage will be completed with value of the final function evaluation when the input stream ends, or completed with Failure if there is a failure is signaled in the stream.

关于scala - 在Akka Streams中,Sink.fold()处理是序列化的吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36461264/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com