sleep()

Suspends a workflow for a specified duration or until an end date without consuming any resources. Once the duration or end date has passed, the workflow will resume execution.

This is useful when you want to resume a workflow after some duration or date.

sleep is a special type of step function provided and should be called directly inside workflow functions.

import { sleep } from "workflow"

async function testWorkflow() {
    "use workflow"
    await sleep("10s") 
}

API Signature

Parameters

This function has multiple signatures.

Signature 1

NameTypeDescription
durationStringValueThe duration to sleep for, this is a string in the format of "1000ms", "1s", "1m", "1h", or "1d".

Signature 2

NameTypeDescription
dateDateThe date to sleep until, this must be a future date.

Examples

Sleeping With a Duration

You can specify a duration for sleep to suspend the workflow for a fixed amount of time.

import { sleep } from "workflow"

async function testWorkflow() {
    "use workflow"
    await sleep("1d") 
}

Sleeping Until an End Date

You can specify a future Date object for sleep to suspend the workflow until a specific date.

import { sleep } from "workflow"

async function testWorkflow() {
    "use workflow"
    await sleep(new Date(Date.now() + 10_000)) 
}