Skip to main content

Parallel

WIO.Parallel allows running multiple branches simultaneously, enabling scenarios such as waiting for a mix of signals and timers without enforcing a particular order.

All paths must incorporate their internal states into a global state (referred to as InterimState).

The final result is constructed from the outcomes of all paths.

val doA = WIO.pure(MyState(1)).autoNamed
val doB = WIO.pure(MyState(2)).autoNamed

val parallel: WIO[Int, Nothing, MyState] =
WIO.parallel
.taking[Int]
.withInterimState(initial => MyState(initial))
.withElement(
logic = doA,
incorporatedWith = (interimState, pathState) => MyState(interimState.counter + pathState.counter),
)
.withElement(
logic = doB,
incorporatedWith = (interimState, pathState) => MyState(interimState.counter - pathState.counter),
)
.producingOutputWith((aOut, bOut) => MyState(aOut.counter * bOut.counter))