1. Waiting for External Events with waitForEvent()
Use waitForEvent() to halt workflow execution until an external signal or webhook is received:
{ durable: true }, the workflow halts at waitForEvent and returns a suspension descriptor:
2. Sleeping with wait()
Pause workflow execution for a deterministic duration without blocking CPU threads:
3. Resuming Suspended Workflows
When an external event occurs (e.g., an incoming webhook), resume the workflow usingresumeWorkflow() or the flow instance’s flow.resume() method:
4. Workflow Versioning and State Migrations
Long-running workflows that span days or weeks may have their code updated while executions are sleeping.Siglo allows declarative state migrations:
Minimal Example
Failure Example: Expired Waits and Duplicate Resumptions
Testing Example
Operational Caveats
- Use Persistent Storage in Production: In production, register
@siglo/postgresor@siglo/redisviauseStorage(). The in-memory default storage is strictly for testing and single-process development. - Correlation Key Uniqueness: Correlation keys must be unique per waiting workflow instance. Using natural business identifiers (e.g.
orderId,ticketId) avoids collision bugs. - Execution Options:
{ durable: true }enables suspension and wait record persistence. When omitted,waitForEventruns in non-durable in-memory fallback mode.
