suspend()
Pauses workflow execution at the current step until explicitly resumed. The workflow state is persisted and can be continued later.
Usage Example
const approvalStep = new Step({
id: "needsApproval",
execute: async ({ context, suspend }) => {
if (context.steps.amount > 1000) {
await suspend();
}
return { approved: true };
}
});
Parameters
metadata?:
Record<string, any>
Optional data to store with the suspended state
Returns
Promise<void>:
Promise
Resolves when the workflow is successfully suspended
Additional Examples
Suspend with metadata:
const reviewStep = new Step({
id: "review",
execute: async ({ context, suspend }) => {
await suspend({
reason: "Needs manager approval",
requestedBy: context.user
});
return { reviewed: true };
}
});
Monitor suspended state:
workflow.watch((state) => {
if (state.status === "SUSPENDED") {
notifyReviewers(state.metadata);
}
});