Signature
Parameters
StringValue
A duration string in the format of
"1000ms", "1s", "1m", "1h", or "1d".Date
A Date object representing when to resume. Must be a future date.
number
The duration to sleep for in milliseconds.
Returns
Promise<void>
A promise that resolves when the sleep duration has elapsed.
Usage
Sleep with Duration String
Pause for a human-readable duration:Sleep with Milliseconds
Pause for a specific number of milliseconds:Sleep Until Specific Date
Pause until a specific point in time:Retry Pattern
Implement exponential backoff:Schedule Future Task
Schedule work for a specific time:Polling with Delays
Poll an external system with delays:Rate Limiting
Control the rate of operations:Duration Format
The sleep function accepts duration strings in the following formats:"1000ms"- Milliseconds"1s"- Seconds"1m"- Minutes"1h"- Hours"1d"- Days
"1h 30m", "2d 3h", etc.
Notes
- Can only be called inside a workflow function (with
"use workflow") - This is a durable sleep that persists across workflow suspensions
- The workflow will be suspended during sleep and resumed when the duration elapses
- Sleep uses timer events in the event log for durability
- When sleeping until a date, the date must be in the future
- Very long sleep durations (months/years) are supported
Related
- RetryableError - Control step retry timing