Workers API

Within a Workflow, can you run a Workflow Step in parallel? For example: The AI SDK allows parallel execution of a step: https://developers.cloudflare.com/workflows/build/workers-api/#call-workflows-from-workers And so does Mastra: https://mastra.ai/en/docs/workflows/control-flow#simultaneous-steps-with-parallel It's not clear if Workflows have this feature.
Cloudflare Docs
Workers API
This guide details the Workflows API within Cloudflare Workers, including methods, types, and usage examples.
Branching, Merging, Conditions | Workflows | Mastra Docs
Control flow in Mastra workflows allows you to manage branching, merging, and conditions to construct workflows that meet your logic requirements.
1 Reply
Olga Silva
Olga Silvathis hour
Hey! By parallel you probably mean concurrently (as from what I see in Mastra docs). You can run concurrent steps with Promise.all(). We have an example here https://developers.cloudflare.com/workflows/build/rules-of-workflows/#do-not-rely-on-state-outside-of-a-step . In short:
const imageList: string[] = await Promise.all([
step.do("get first cutest cat from KV", async () => {
return await env.KV.get("cutest-http-cat-1");
}),

step.do("get second cutest cat from KV", async () => {
return await env.KV.get("cutest-http-cat-2");
}),
]);
const imageList: string[] = await Promise.all([
step.do("get first cutest cat from KV", async () => {
return await env.KV.get("cutest-http-cat-1");
}),

step.do("get second cutest cat from KV", async () => {
return await env.KV.get("cutest-http-cat-2");
}),
]);
Let me know if this is what you were looking for

Did you find this page helpful?