Sink.foreachAsync
Invoke a given procedure asynchronously for each element received.
Signature
Description
Invoke a given procedure asynchronously for each element received. Note that if shared state is mutated from the procedure that must be done in a thread-safe way.
The sink materializes into a Future[Done]
which completes when the stream completes, or fails if the stream fails.
See also:
foreach
Invoke a given procedure for each element received.actorRef
Send the elements from the stream to anActorRef
.
Example
- Scala
-
source
//def asyncProcessing(value: Int): Future[Unit] = _ Source(1 to 100).runWith(Sink.foreachAsync(10)(asyncProcessing))
- Java
Reactive Streams semantics
cancels when a Future
fails
backpressures when the number of Future
s reaches the configured parallelism