Parallel Flows
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. Workflow's state is continously updated after each step completion (doesn't wait for all the paths to complete.)
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))
Rendering Outputs
- Flowchart
- BPMN
- Model
{
"elements" : [
{
"meta" : {
"name" : "Do A",
"error" : null
},
"_type" : "Pure"
},
{
"meta" : {
"name" : "Do B",
"error" : null
},
"_type" : "Pure"
}
],
"_type" : "Parallel"
}