Skip to main content

Interrupting Execution

Interruption operations are crucial for workflows that need to respond to cancellation requests or timeout conditions. This allows selecting an alternative path based on such a signal.

val MySignal = SignalDef[MyRequest, MyResponse]()
val doA = WIO.pure(MyState(1)).autoNamed
val doB = WIO.pure(MyState(1)).autoNamed

val interruption =
WIO.interruption
.throughSignal(MySignal)
.handleSync((state, request) => MyEvent())
.handleEvent((state, event) => MyState(0))
.produceResponse((state, event) => MyResponse())
.autoNamed
.andThen(_ >>> doB)

val interruptedThroughSignal = doA.interruptWith(interruption)
Rendering Outputs

Drafting Support

Interruptions come with drafting support.

// Create signal and timeout interruptions
val urgentProcessing = WIO.draft.interruptionSignal("Urgent Processing Request")
val processingTimeout = WIO.draft.interruptionTimeout("Processing Deadline", 2.hours)

// Document processing workflow that can be interrupted
val documentProcessingWorkflow =
WIO.draft.step("Validate Document") >>>
WIO.draft
.step("Extract Content")
.interruptWith(urgentProcessing) // Can be interrupted for urgent processing
.interruptWith(processingTimeout) // Must complete within 2 hours
Rendering Outputs