I have several Flow
s in my program, that I would like to process in parallel. After all are completed, I would like to trigger some action.
One way of doing it would be to send a message to an Actor after each completion, and when the Actor verifies that all flows are ready, then it can trigger the action.
I was wondering if there was anything within the akka-streams Scala DSL that I may be overlooking that would make it even simpler.
EDIT: Converting a Flow to a future would not work because, as the documentation mentions, the Future is completed right after the first event that happens in the stream. Running the following code:
implicit val system = ActorSystem("Sys")
val fm = FlowMaterializer(MaterializerSettings())
def main(args: Array[String]): Unit = {
val fut = Flow(1 second, {() => println("tick")}).toFuture(fm)
fut.onComplete{ _ =>
println("future completed")
}
}
Prints "tick", followed by "future completed", and then an infinite sequence of "tick"s.
Flow
produces anotherFlow
. If you perform several transforms and then use the finalFlow
instance to calltoFuture
, thatFuture
should only be satisfied when all of the preceding transforms have been completed. – cmbaxter