Skip to content

Commit 5aebb7a

Browse files
committed
Concurrency simulator
1 parent 7bf2a9a commit 5aebb7a

File tree

4 files changed

+606
-0
lines changed

4 files changed

+606
-0
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,6 @@
1818
npm-debug.log*
1919
yarn-debug.log*
2020
yarn-error.log*
21+
22+
docker*
23+
Docker*

docs/features/concurrency.md

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
sidebar_position: 8
33
---
44

5+
import ConcurrencySimulator from '@site/src/components/ConcurrencySimulator';
6+
57
# Concurrency
68

79
Activities can be executed in series or in parallel. In either case, you start by using `activity()` to create a new instance of an activity and return a promise that represents the execution of that activity. The activity will immediately begin executing in the background. You can then `yield` this promise to pause the execution of the workflow and wait for the result of the activity, or pass the promise into the `all()` method to wait for a group of activities to complete in parallel.
@@ -27,6 +29,16 @@ class MyWorkflow extends Workflow
2729
}
2830
```
2931

32+
<ConcurrencySimulator
33+
activities={[
34+
{ name: 'MyActivity1', duration: 1500 },
35+
{ name: 'MyActivity2', duration: 2000 },
36+
{ name: 'MyActivity3', duration: 1200 },
37+
]}
38+
mode="series"
39+
title="Series Execution Simulator"
40+
/>
41+
3042
## Parallel
3143

3244
This example will execute 3 activities in parallel, waiting for the completion of all activities and collecting the results.
@@ -48,6 +60,16 @@ class MyWorkflow extends Workflow
4860
}
4961
```
5062

63+
<ConcurrencySimulator
64+
activities={[
65+
{ name: 'MyActivity1', duration: 2000 },
66+
{ name: 'MyActivity2', duration: 1500 },
67+
{ name: 'MyActivity3', duration: 2500 },
68+
]}
69+
mode="parallel"
70+
title="Parallel Execution Simulator"
71+
/>
72+
5173
The main difference between the serial example and the parallel execution example is the number of `yield` statements. In the serial example, there are 3 `yield` statements, one for each activity. This means that the workflow will pause and wait for each activity to complete before continuing to the next one. In the parallel example, there is only 1 `yield` statement, which wraps all of the activities in a call to `all()`. This means that all of the activities will be executed in parallel, and the workflow will pause and wait for all of them to complete as a group before continuing.
5274

5375
## Mix and Match
@@ -82,6 +104,19 @@ class MyWorkflow extends Workflow
82104

83105
Activity 1 will execute and complete before any other activities start. Activities 2 and 3 will execute in series, waiting for each to complete one after another before continuing. At the same time, activities 4 and 5 will execute together in parallel and only when they all complete will execution continue. Finally, activity 6 executes last after all others have completed.
84106

107+
<ConcurrencySimulator
108+
activities={[
109+
{ name: 'MyActivity1', duration: 1200, group: 0 },
110+
{ name: 'MyActivity2', duration: 1000, group: 1, subgroup: 'a' },
111+
{ name: 'MyActivity3', duration: 1200, group: 1, subgroup: 'a' },
112+
{ name: 'MyActivity4', duration: 1800, group: 1 },
113+
{ name: 'MyActivity5', duration: 1400, group: 1 },
114+
{ name: 'MyActivity6', duration: 1000, group: 2 },
115+
]}
116+
mode="mix"
117+
title="Mix and Match Simulator"
118+
/>
119+
85120
## Child Workflows in Parallel
86121

87122
You can pass child workflows to `all()` along with other activities. It works the same way as parallel activity execution, but for child workflows. It allows you to fan out multiple child workflows and wait for all of them to complete together.
@@ -96,4 +131,14 @@ $results = yield all([
96131
]);
97132
```
98133

134+
<ConcurrencySimulator
135+
activities={[
136+
{ name: 'MyChild1', duration: 2200 },
137+
{ name: 'MyChild2', duration: 1800 },
138+
{ name: 'MyChild3', duration: 2500 },
139+
]}
140+
mode="parallel"
141+
title="Child Workflows in Parallel Simulator"
142+
/>
143+
99144
This makes it easy to build hierarchical parallelism into your workflows.

0 commit comments

Comments
 (0)