Siglo supports durable suspension and resumption without keeping active event listeners or worker processes running in memory.
1. Durable Execution Mode (durable: true)
When a workflow runs with { durable: true }, encounter of a wait node halts execution cleanly, creates a state checkpoint, records a waiting descriptor, and returns execution control with status 'waiting':
{ durable: true } and hits a wait node, Siglo throws a WorkflowSuspendedException containing the waiting descriptor.
2. Wait Combinators
waitForEvent(eventName, options)
Waits for an incoming event correlated by key:
correlationKey: String or dynamic context selector(ctx) => string.timeout/timeoutMs: Duration string (e.g.'2h','30m','7d') or milliseconds.
wait(duration, options?)
Durable sleep/timer that suspends workflow execution:
duration: Duration string (e.g.'24h','15m','60s') or numeric milliseconds.
3. Resuming Workflows (flow.resume / resumeWorkflow)
When the external event occurs (e.g. from an HTTP webhook), resume the workflow by passing the correlation key or stackId and the external event payload:
resumeWorkflow utility:
Resumption Lifecycle
- Wait Record Validation: Resolves the wait record from
DurableManageror storage adapter (claimWaitRecord). - State Restoration: Restores context and
$stepshistory snapshots from the checkpoint. - Event Payload Merge: Merges incoming event payload into the execution context.
- Continuation Execution: Evaluates remaining steps starting at
continuationStepIndexwithout re-running completed steps.
4. Event Safety & Concurrency Guarantees
- Duplicate Resumption Defense:
- In-memory runs: Resuming an already-resumed or non-waiting workflow throws
DuplicateEventException. - Storage-backed runs: Concurrent claims on the same wait record throw
WorkflowAlreadyResumedException.
- In-memory runs: Resuming an already-resumed or non-waiting workflow throws
- Expired Wait Enforcement: If an event arrives after the declared
timeouthas elapsed,ExpiredWaitExceptionis thrown (unless explicitly overridden withallowExpired: true). - Resource Efficiency: In-memory timers and context closures are freed while suspended, allowing thousands of workflows to pause concurrently in production without resource leaks.
5. Human-in-the-Loop Approvals
For production human intervention flows (interactive Slack Block Kit cards, responsive HTML emails, signed HMAC action URLs, two-way Twilio SMS, and web framework callback routers), use@siglo/notifications. It pairs sendInteractiveApprovalStep with waitForEvent and provides signed bearer tokens with application-provided authorization, distributed concurrency claims, and automated saga rollback.