---
title: "Pause with sleep()"
description: "Add sleep() between the kitchen step and the rest of the workflow. Deploy a code change mid-sleep and watch the workflow survive untouched."
canonical_url: "https://vercel.com/academy/workflow-foundations/pause-between-steps-with-sleep"
md_url: "https://vercel.com/academy/workflow-foundations/pause-between-steps-with-sleep.md"
docset_id: "vercel-academy"
doc_version: "1.0"
last_updated: "2026-10-20T22:57:37.709Z"
content_type: "lesson"
course: "workflow-foundations"
course_title: "Build Durable Workflows"
prerequisites:  []
---

<agent-instructions>
Vercel Academy — structured learning, not reference docs.
Lessons are sequenced.
Adapt commands to the human's actual environment (OS, package manager, shell, editor) — detect from project context or ask, don't assume.
The lesson shows one path; if the human's project diverges, adapt concepts to their setup.
Preserve the learning goal over literal steps.
Quizzes are pedagogical — engage, don't spoil.
Quiz answers are included for your reference.
</agent-instructions>

# Pause with sleep()

# Pause between steps with sleep()

Pizzas take time to cook. The workflow has no idea.

If we want it to wait for the kitchen before dispatching a driver, we need a way to pause. In a regular Node app, pausing means a `setTimeout` and praying the process stays alive. In a serverless function it means... well, you don't pause. Your function dies after 10 seconds.

Workflows have `sleep()`. You await it like any other promise. The workflow suspends. Vercel stops running anything related to that workflow, no compute, no memory, nothing. When the time elapses, the workflow picks up exactly where it left off.

Today we're going to pause for 30 seconds between the kitchen ack and the next step. Boring on paper. The reason to pay attention: while the workflow is sleeping, we're going to deploy a code change. The workflow should survive it untouched.

## Outcome

Add `await sleep("30s")` to `processOrder` after the kitchen step. Deploy a change while a workflow is mid-sleep and watch the original run complete cleanly.

## Fast Track

1. Import `sleep` from `workflow` in `workflows/process-order.ts`. Add `await sleep("30s")` after `acknowledgeKitchen`.
2. Deploy. Place an order. While the dashboard shows the workflow suspended, change the confirmation email subject and push another deploy.
3. Watch the original run finish on the new build without re-running the steps that already completed.

## Hands-on exercise

**1. Add sleep.**

Update `workflows/process-order.ts`:

```ts title="workflows/process-order.ts" {1,10}
import { sleep } from "workflow";
import type { Order } from "@/lib/pizza";
import { sendOrderConfirmation } from "./steps/send-order-confirmation";
import { acknowledgeKitchen } from "./steps/acknowledge-kitchen";

export async function processOrder(order: Order): Promise<{ orderId: string }> {
  "use workflow";

  await sendOrderConfirmation(order);
  await acknowledgeKitchen(order);
  await sleep("30s");

  return { orderId: order.id };
}
```

`sleep()` accepts a duration string like `"30s"`, `"5m"`, `"7 days"`, or a number of milliseconds. We're using 30 seconds because it's long enough to deploy through.

**2. Deploy.**

```bash
git add .
git commit -m "feat(workflow): pause after kitchen ack"
git push
```

Wait for Vercel to finish the deploy.

## Try It

This is the experiment. Pay attention to the timestamps.

**Place an order on your production URL.** The workflow runs `sendOrderConfirmation`, then `acknowledgeKitchen`, then hits `sleep("30s")` and suspends.

**Open the Workflows dashboard** in your Vercel project. The run shows as `running` with the timeline ending at the sleep:

```
processOrder              running
  ├─ sendOrderConfirmation  completed
  └─ acknowledgeKitchen     completed
  ─ sleeping 30s
```

**While that's suspended, change something.** Open `workflows/steps/send-order-confirmation.ts` and edit the email subject. Add an emoji. Add "v2". Anything. Then:

```bash
git commit -am "tweak: update confirmation subject"
git push
```

Vercel builds and ships the new version.

**Now go back to the original run.** The sleep elapses. The workflow wakes up on the new deploy. It finishes:

```
processOrder              completed   30.4s
  ├─ sendOrderConfirmation  completed   389ms
  └─ acknowledgeKitchen     completed   208ms
       (slept 30s, resumed after deploy)
```

The completed steps don't re-run. The new code is now serving new orders, but the old order finishes on the timeline it started with.

This is the unfair part of durable execution. It's also why the directives exist.

\*\*Note: What just happened\*\*

Two things kept the original workflow safe across a deploy: every step's input/output was already persisted to the event log, and `sleep()` doesn't hold a process open. When Vercel restarted the workflow on the new deploy, it replayed the workflow function from the top, hit each completed step, looked up the recorded result, and skipped ahead. It only actually executed code starting from where the workflow had paused.

## Commit

```
feat(workflow): pause after kitchen with sleep()
```

## Done-When

- [ ] `workflows/process-order.ts` imports `sleep` from `workflow`
- [ ] The workflow awaits `sleep("30s")` after `acknowledgeKitchen`
- [ ] You've shipped a code change while a workflow was mid-sleep
- [ ] The original run completed on the new deploy without re-running prior steps

## Solution

```ts title="workflows/process-order.ts"
import { sleep } from "workflow";
import type { Order } from "@/lib/pizza";
import { sendOrderConfirmation } from "./steps/send-order-confirmation";
import { acknowledgeKitchen } from "./steps/acknowledge-kitchen";

export async function processOrder(order: Order): Promise<{ orderId: string }> {
  "use workflow";

  await sendOrderConfirmation(order);
  await acknowledgeKitchen(order);
  await sleep("30s");

  return { orderId: order.id };
}
```

One line. Workflow sleeps. Deploys don't matter. This is the closest thing this course has to a magic trick.


---

[Full course index](/academy/llms.txt) · [Sitemap](/academy/sitemap.md)
