Workflow.sleep and Workflow.sleepUntil pause workflow execution in a fully durable way. Unlike Effect.sleep, these primitives persist the wake-up time to Durable Object storage and schedule a Cloudflare alarm to resume. The workflow picks up exactly where it left off — even across deployments and server restarts.
Workflow.sleep
Pause the workflow for a relative duration.Signature
Parameters
How long to sleep. Accepts a human-readable duration string or a number of milliseconds.String formats:
Number: milliseconds, e.g.
| Format | Example |
|---|---|
| Seconds | "30 seconds", "30s", "30 sec" |
| Minutes | "5 minutes", "5m", "5 min" |
| Hours | "2 hours", "2h", "2 hr" |
| Days | "7 days", "7d", "7 day" |
| Milliseconds | "500ms", "500 milliseconds" |
5000 for 5 seconds.Examples
Workflow.sleepUntil
Pause the workflow until an absolute Unix timestamp (milliseconds).Signature
Parameters
Unix timestamp in milliseconds at which the workflow should resume. If
the timestamp is already in the past, the sleep is skipped and execution
continues immediately.
Example
How durable sleep works
WhenWorkflow.sleep is called:
- The wake-up timestamp is persisted to Durable Object storage.
- A Cloudflare Durable Object alarm is scheduled for the wake-up time.
- The workflow pauses execution by emitting a
PauseSignal. - When the alarm fires, the workflow resumes and the sleep is marked complete.
- On subsequent replays, the completed sleep is detected from storage and skipped.
Workflow.sleep and Workflow.sleepUntil can only be called at the top
level of a workflow, not inside a Workflow.step. Calling them inside a step
will produce a compile-time error via the WorkflowLevel context guard.DurationInput type
Bothsleep and timeout in Workflow.step accept the DurationInput type:
parseDuration. Supported units:
