summaryrefslogtreecommitdiff
path: root/tests/temporal/Workflow/SimpleSignalledWorkflowWithSleep.php
blob: d10ba04a551db5f4599e66ff826b96efbb65049e (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
32
33
34
<?php

declare(strict_types=1);

namespace Temporal\Tests\Workflow;

use Temporal\Workflow;
use Temporal\Workflow\WorkflowMethod;

#[Workflow\WorkflowInterface]
class SimpleSignalledWorkflowWithSleep
{
    private $counter = 0;

    #[Workflow\SignalMethod(name: "add")]
    public function add(
        int $value
    ) {
        $this->counter += $value;
    }

    #[WorkflowMethod(name: 'SimpleSignalledWorkflowWithSleep')]
    public function handler(): iterable
    {
        // collect signals during one second
        yield Workflow::timer(1);

        if (!Workflow::isReplaying()) {
            sleep(1);
        }

        return $this->counter;
    }
}