const [result1, result2, result3] =
await Promise.all([
ctx.run("parallel-step-1", async () => { ... }),
ctx.run("parallel-step-2", async () => { ... }),
ctx.run("parallel-step-3", async () => { ... }),
])
app/api/workflow/route.ts
import { serve } from "@upstash/workflow/nextjs"
import { checkInventory, brewCoffee, printReceipt } from "@/utils"
export const { POST } = serve(async (ctx) => {
const [coffeeBeansAvailable, cupsAvailable, milkAvailable] =
await Promise.all([
ctx.run("check-coffee-beans", () => checkInventory("coffee-beans")),
ctx.run("check-cups", () => checkInventory("cups")),
ctx.run("check-milk", () => checkInventory("milk")),
])
if (coffeeBeansAvailable && cupsAvailable && milkAvailable) {
const price = await ctx.run("brew-coffee", async () => {
return await brewCoffee({ style: "cappuccino" })
})
await printReceipt(price)
}
})