简体   繁体   中英

In Akka Streams, is Sink.fold() processing serialized?

I am getting started with Akka streams; I am trying to create a stream that reads data from a web service and then persists them in S3. I was wondering, if I define a Sink using the Sink.fold method (in order to gather information about the persisted elements) for the persistence, are the elements sent to the sink going to be processed one after another, or in parallel?

It's a basic question, but I wasn't able to find a definitive answer in the docs.

Since Sink.fold needs the result from the previous elements to combine it with the next one, it's necessarily sequential.

It's more of a Sink.foldLeft , actually.

In other words, if you have a, b as elements, and you fold them using f , you need acc = f(zero, a) to be able to process f(acc, b) . So, until the processing for a is done b cannot be processed.

From the 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM