Run Workflow Steps in Parallel

In this chapter, you’ll learn how to run workflow steps in parallel.

parallelize Utility Function#

If your workflow has steps that don’t rely on one another’s results, run them in parallel using parallelize from the Workflows SDK.

The workflow waits until all steps passed to the parallelize function finish executing before continuing to the next step.

For example:

Code
11} from "./steps"12
13interface WorkflowInput {14  title: string15}16
17const myWorkflow = createWorkflow(18  "my-workflow", 19  (input: WorkflowInput) => {20   const product = createProductStep(input)21
22   const [prices, productSalesChannel] = parallelize(23     createPricesStep(product),24     attachProductToSalesChannelStep(product)25   )26
27   const id = product.id28   const refetchedProduct = getProductStep(product.id)29
30   return new WorkflowResponse(refetchedProduct)31 }32)

The parallelize function accepts the steps to run in parallel as a parameter.

It returns an array of the steps' results in the same order they're passed to the parallelize function.

So, prices is the result of createPricesStep, and productSalesChannel is the result of attachProductToSalesChannelStep.

Was this chapter helpful?
Edit this page
Ask Anything
FAQ
What is Medusa?
How can I create a module?
How can I create a data model?
How do I create a workflow?
How can I extend a data model in the Product Module?
Recipes
How do I build a marketplace with Medusa?
How do I build digital products with Medusa?
How do I build subscription-based purchases with Medusa?
What other recipes are available in the Medusa documentation?
Chat is cleared on refresh
Line break