Skip to main content
Durable workflows allow executions to sleep, suspend, wait for external human approvals or webhooks, survive process restarts, and resume safely days or months later.

1. Waiting for External Events with waitForEvent()

Use waitForEvent() to halt workflow execution until an external signal or webhook is received:
When run with { 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 using resumeWorkflow() 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

  1. Use Persistent Storage in Production: In production, register @siglo/postgres or @siglo/redis via useStorage(). The in-memory default storage is strictly for testing and single-process development.
  2. Correlation Key Uniqueness: Correlation keys must be unique per waiting workflow instance. Using natural business identifiers (e.g. orderId, ticketId) avoids collision bugs.
  3. Execution Options: { durable: true } enables suspension and wait record persistence. When omitted, waitForEvent runs in non-durable in-memory fallback mode.