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/side-effects.md
+36Lines changed: 36 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -24,3 +24,39 @@ class MyWorkflow extends Workflow
24
24
The workflow will only call `random_int()` once and save the result, even if the workflow later fails and is retried.
25
25
26
26
**Important:** The code inside a side effect should never fail because it will not be retried. Code that can possibly fail and therefore need to be retried should be moved to an activity instead.
27
+
28
+
## Signals and Control Flow
29
+
30
+
Signals are applied before the workflow continues execution. That means a signal-mutated variable can break replays unless the control flow decision is recorded deterministically.
31
+
32
+
Use `sideEffect` to snapshot any signal-driven branch decision:
33
+
34
+
```php
35
+
use function Workflow\{activity, sideEffect};
36
+
use Exception;
37
+
use Workflow\SignalMethod;
38
+
use Workflow\Workflow;
39
+
40
+
class MyWorkflow extends Workflow
41
+
{
42
+
private bool $cancelled = false;
43
+
44
+
#[SignalMethod]
45
+
public function cancel()
46
+
{
47
+
$this->cancelled = true;
48
+
}
49
+
50
+
public function execute()
51
+
{
52
+
while (true) {
53
+
yield activity(MyActivity::class);
54
+
55
+
if (yield sideEffect(fn () => $this->cancelled)) {
56
+
throw new Exception('Workflow cancelled by signal.');
57
+
}
58
+
}
59
+
}
60
+
```
61
+
62
+
This keeps control flow replay-safe and avoids non-deterministic branching during signal handling.
0 commit comments