How to handle Signals in an Workflow in PHP
Use the #[SignalMethod]
annotation to handle Signals in the Workflow interface:
use Temporal\Workflow;
#[Workflow\WorkflowInterface]
class YourWorkflow
{
private bool $value;
#[Workflow\WorkflowMethod]
public function run()
{
yield Workflow::await(fn()=> $this->value);
return 'OK';
}
#[Workflow\SignalMethod]
public function setValue(bool $value)
{
$this->value = $value;
}
}
In the example above the workflow updates the protected value. Main workflow coroutine waits for such value to change using
Workflow::await()
function.