summaryrefslogtreecommitdiff
path: root/tests/temporal/Workflow/RuntimeSignalWorkflow.php
blob: f700af72f42cb628c96ad8a57e812da4dabc1dd9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
<?php

namespace Temporal\Tests\Workflow;

use React\Promise\Deferred;
use Temporal\Workflow;
use Temporal\Workflow\WorkflowMethod;

#[Workflow\WorkflowInterface]
class RuntimeSignalWorkflow
{
    #[WorkflowMethod]
    public function handler()
    {
        $wait1 = new Deferred();
        $wait2 = new Deferred();

        $counter = 0;

        Workflow::registerSignal('add', function ($value) use (&$counter, $wait1, $wait2) {
            $counter += $value;
            $wait1->resolve($value);
            $wait2->resolve($value);
        });

        yield $wait1;
        yield $wait2;

        return $counter;
    }
}