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/signals.md
+32Lines changed: 32 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -63,3 +63,35 @@ class MyWorkflow extends Workflow
63
63
<SignalSimulator />
64
64
65
65
**Important:** The `await()` function should only be used in a workflow, not an activity.
66
+
67
+
## Inbox
68
+
69
+
Workflows often need to handle multiple incoming signals over time. To solve this, workflows include a built-in replay-safe `$this->inbox`.
70
+
71
+
The inbox collects incoming signal values and lets you consume them exactly once, even if the workflow is replayed or resumed multiple times.
72
+
73
+
```php
74
+
use function Workflow\await;
75
+
use Workflow\SignalMethod;
76
+
use Workflow\Workflow;
77
+
78
+
class MyWorkflow extends Workflow
79
+
{
80
+
#[SignalMethod]
81
+
public function receive(string $message): void
82
+
{
83
+
$this->inbox->receive($message);
84
+
}
85
+
86
+
public function execute()
87
+
{
88
+
while (true) {
89
+
yield await(fn () => $this->inbox->hasUnread());
90
+
91
+
$message = $this->inbox->nextUnread();
92
+
}
93
+
}
94
+
}
95
+
```
96
+
97
+
Each received signal is stored in the inbox. The inbox tracks which messages have already been read. On replay, previously read messages remain read. Only unread messages are returned by `nextUnread()`. This makes the inbox safe to use in `await()` conditions and inside long-running loops.
0 commit comments