Awaiting Signals
Signal handling is essential for workflows that need to pause and wait for external events before proceeding. This operation allows workflows to respond to user actions, system notifications, or other asynchronous events, making it ideal for human-in-the-loop processes or integration with external systems.
val MySignal = SignalDef[MyRequest, MyResponse]()
val doThings: WIO[MyState, Nothing, MyState] =
WIO
.handleSignal(MySignal)
.using[MyState]
.withSideEffects((state, request) => IO(MyEvent()))
.handleEvent((state, event) => state)
.produceResponse((state, event) => MyResponse())
.autoNamed
Rendering Outputs
- Flowchart
- BPMN
- Model
{
"meta" : {
"signalName" : "My Request",
"operationName" : "Do Things",
"error" : null
},
"_type" : "HandleSignal"
}
Unhandled Signals
The Workflows4s API allows arbitrary signals to be sent to a workflow instance. While this provides flexibility, it also requires developers to be disciplined and diligent, with thorough tests to ensure only valid signals are passed.
Technically, it is possible to constrain signals to a specific ADT, similar to how state and events are managed. However, doing so would introduce significant complexity without fully eliminating unhandled signals. By design, signals are only expected at specific moments in a workflow's lifecycle, meaning unhandled signals can still occur outside those windows.