Skip to content

Commit 84e6eb2

Browse files
authored
Document inbox feature for signal handling in workflows
Added documentation on handling incoming signals in workflows using the inbox feature.
1 parent 6300c09 commit 84e6eb2

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

docs/features/signals.md

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,3 +63,35 @@ class MyWorkflow extends Workflow
6363
<SignalSimulator />
6464

6565
**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

Comments
 (0)