Loops
Loops are essential for workflows that need to repeat actions until a condition is met. This operation enables iterative processing, such as retrying operations, processing collections of items, or implementing polling mechanisms that continue until specific criteria are satisfied.
warning
Loops without timers or signals will be effectively busy loops, possibly causing journal growth and other problems. Consider adding a short timer to slow it down. In the future this will be detected by the linter.
val step1 = WIO.pure(MyState(1)).autoNamed
val step2 = WIO.pure(MyState(1)).autoNamed
val loop: WIO[MyState, Nothing, MyState] = WIO
.repeat(step1)
.untilSome(state => Some(state))
.onRestart(step2)
.named(
conditionName = "Is everything done?",
releaseBranchName = "Yes!",
restartBranchName = "No",
)
Rendering Outputs
- Flowchart
- BPMN
- Model
{
"base" : {
"meta" : {
"name" : "Step1",
"error" : null
},
"_type" : "Pure"
},
"onRestart" : {
"meta" : {
"name" : "Step2",
"error" : null
},
"_type" : "Pure"
},
"meta" : {
"conditionName" : "Is everything done?",
"exitBranchName" : "Yes!",
"restartBranchName" : "No"
},
"_type" : "Loop"
}