You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/features/child-workflows.md
+24-26Lines changed: 24 additions & 26 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -6,17 +6,17 @@ sidebar_position: 7
6
6
7
7
It's often necessary to break down complex processes into smaller, more manageable units. Child workflows provide a way to encapsulate a sub-process within a parent workflow. This allows you to create hierarchical and modular structures for your workflows, making them more organized and maintainable.
8
8
9
-
A child workflow is just like any other workflow. The only difference is how it's invoked within the parent workflow, using `ChildWorkflowStub::make()`.
9
+
A child workflow is just like any other workflow. The only difference is how it's invoked within the parent workflow, using `child()`.
@@ -127,16 +126,15 @@ class ParentWorkflow extends Workflow
127
126
You can access the underlying stored workflow ID using the `id()` method. This allows you to store the ID for external systems to signal the child directly.
@@ -183,19 +181,19 @@ if ($childId = $workflow->childId()) {
183
181
184
182
## Async Activities
185
183
186
-
Rather than creating a child workflow, you can pass a callback to `ActivityStub::async()` and it will be executed in the context of a separate workflow.
184
+
Rather than creating a child workflow, you can pass a callback to `async()` and it will be executed in the context of a separate workflow.
Copy file name to clipboardExpand all lines: docs/features/concurrency.md
+26-26Lines changed: 26 additions & 26 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -4,24 +4,24 @@ sidebar_position: 8
4
4
5
5
# Concurrency
6
6
7
-
Activities can be executed in series or in parallel. In either case, you start by using `ActivityStub::make()` 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 `ActivityStub::all()` method to wait for a group of activities to complete in parallel.
7
+
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.
8
8
9
9
## Series
10
10
11
11
This example will execute 3 activities in series, waiting for the completion of each activity before continuing to the next one.
12
12
13
13
```php
14
-
use Workflow\ActivityStub;
14
+
use function Workflow\activity;
15
15
use Workflow\Workflow;
16
16
17
17
class MyWorkflow extends Workflow
18
18
{
19
19
public function execute()
20
20
{
21
21
return [
22
-
yield ActivityStub::make(MyActivity1::class),
23
-
yield ActivityStub::make(MyActivity1::class),
24
-
yield ActivityStub::make(MyActivity1::class),
22
+
yield activity(MyActivity1::class),
23
+
yield activity(MyActivity1::class),
24
+
yield activity(MyActivity1::class),
25
25
];
26
26
}
27
27
}
@@ -32,47 +32,47 @@ class MyWorkflow extends Workflow
32
32
This example will execute 3 activities in parallel, waiting for the completion of all activities and collecting the results.
33
33
34
34
```php
35
-
use Workflow\ActivityStub;
35
+
use function Workflow\{activity, all};
36
36
use Workflow\Workflow;
37
37
38
38
class MyWorkflow extends Workflow
39
39
{
40
40
public function execute()
41
41
{
42
-
return yield ActivityStub::all([
43
-
ActivityStub::make(MyActivity1::class),
44
-
ActivityStub::make(MyActivity2::class),
45
-
ActivityStub::make(MyActivity3::class),
42
+
return yield all([
43
+
activity(MyActivity1::class),
44
+
activity(MyActivity2::class),
45
+
activity(MyActivity3::class),
46
46
]);
47
47
}
48
48
}
49
49
```
50
50
51
-
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 `ActivityStub::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.
51
+
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.
52
52
53
53
## Mix and Match
54
54
55
55
You can also mix serial and parallel executions as desired.
56
56
57
57
```php
58
-
use Workflow\ActivityStub;
58
+
use function Workflow\{activity, all, async};
59
59
use Workflow\Workflow;
60
60
61
61
class MyWorkflow extends Workflow
62
62
{
63
63
public function execute()
64
64
{
65
65
return [
66
-
yield ActivityStub::make(MyActivity1::class),
67
-
yield ActivityStub::all([
68
-
ActivityStub::async(fn () => [
69
-
yield ActivityStub::make(MyActivity2::class),
70
-
yield ActivityStub::make(MyActivity3::class),
66
+
yield activity(MyActivity1::class),
67
+
yield all([
68
+
async(fn () => [
69
+
yield activity(MyActivity2::class),
70
+
yield activity(MyActivity3::class),
71
71
]),
72
-
ActivityStub::make(MyActivity4::class),
73
-
ActivityStub::make(MyActivity5::class),
72
+
activity(MyActivity4::class),
73
+
activity(MyActivity5::class),
74
74
]),
75
-
yield ActivityStub::make(MyActivity6::class),
75
+
yield activity(MyActivity6::class),
76
76
];
77
77
}
78
78
}
@@ -84,15 +84,15 @@ Activity 1 will execute and complete before any other activities start. Activiti
84
84
85
85
## Child Workflows in Parallel
86
86
87
-
You can pass child workflows to `ActivityStub::all()` along with with other activities (but we also provide `ChildWorkflowStub::all()` if you prefer). Both of these are just thin wrappers for React Promise's `all()`. 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.
87
+
You can pass child workflows to `all()` along with with other activities. Both of these are just thin wrappers for React Promise's `all()`. 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.
0 commit comments