Sequential Execution
The simplest way to orchestrate steps is to execute them one after another, where each step can be dependent on the previous step.Parallel Execution
When you need to execute multiple steps in parallel, you can usePromise.all to run them all at the same time.
sleep() and webhook are also just promises, we can await those in parallel too. We can also use Promise.race instead of Promise.all to stop executing promises after the first one completes.
A Full Example
Here’s a simplified example taken from the birthday card generator demo, to illustrate how sequential and parallel execution can be combined.Timeout Pattern
A common requirement is adding timeouts to operations that might take too long. UsePromise.race with sleep() to implement this pattern.
Workflow Composition
Workflows can call other workflows, enabling you to break complex processes into reusable building blocks. There are two approaches depending on your needs.Direct Await (Flattening)
Call a child workflow directly usingawait. This “flattens” the child workflow into the parent - the child’s steps execute inline within the parent workflow’s context.
Background Execution via Step
To run a child workflow independently without blocking the parent, use a step that callsstart(). This launches the child workflow in the background.
runId.
Choose direct await when:
- The parent needs the child’s result before continuing
- You want a single, unified event log
- The parent doesn’t need to wait for the result
- You want separate workflow runs for observability