Skip to main content

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 example

workflow.sleep(5000);

Parameters

milliseconds:

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

Returns

workflow:

Workflow
The workflow instance for method chaining

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