Procházet zdrojové kódy

refactor: improve workflow example (#2320)

* refactor: improve workflow example with better structure and async handling

* refactor: improve workflow example with better structure
Vu Son před 7 měsíci
rodič
revize
34aa2baee9
1 změnil soubory, kde provedl 16 přidání a 14 odebrání
  1. 16 14
      src/workflows/README.md

+ 16 - 14
src/workflows/README.md

@@ -7,9 +7,10 @@ The workflow is created in a TypeScript or JavaScript file under the `src/workfl
 For example:
 
 ```ts
-import { 
+import {
   createStep,
   createWorkflow,
+  WorkflowResponse,
   StepResponse,
 } from "@medusajs/framework/workflows-sdk"
 
@@ -29,23 +30,24 @@ const step2 = createStep(
 )
 
 type WorkflowOutput = {
-  message: string
+  message1: string
+  message2: string
 }
 
-const myWorkflow = createWorkflow<
-  WorkflowInput,
-  WorkflowOutput
->("hello-world", function (input) {
-  const str1 = step1()
-  // to pass input
-  step2(input)
-
-  return {
-    message: str1,
+const helloWorldWorkflow = createWorkflow(
+  "hello-world",
+  (input: WorkflowInput) => {
+    const greeting1 = step1()
+    const greeting2 = step2(input)
+    
+    return new WorkflowResponse({
+      message1: greeting1,
+      message2: greeting2
+    })
   }
-})
+)
 
-export default myWorkflow
+export default helloWorldWorkflow
 ```
 
 ## Execute Workflow