Skip to main content
Mastra v1 is coming in January 2026. Get ahead by starting new projects with the beta or upgrade your existing project today.

Workflow.sleep()

The .sleep() method pauses execution for a specified number of milliseconds. It accepts either a static number or a callback function for dynamic delays.

Usage exampleDirect link to Usage example

workflow.sleep(5000);

ParametersDirect link to Parameters

milliseconds:

number | ((context: { inputData: any }) => number | Promise<number>)
The number of milliseconds to pause execution, or a callback that returns the delay

ReturnsDirect link to Returns

workflow:

Workflow
The workflow instance for method chaining

Extended usage exampleDirect link to Extended usage example

import { createWorkflow, createStep } from "@mastra/core/workflows";

const step1 = createStep({...});
const step2 = createStep({...});

export const testWorkflow = createWorkflow({...})
.then(step1)
.sleep(async ({ inputData }) => {
const { delayInMs } = inputData;
return delayInMs;
})
.then(step2)
.commit();

On this page