blob: c389fd78e67bca15bc152c2cda0785e57ab67234 (
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
|
<?php
namespace Temporal\Tests\Workflow;
use Temporal\Activity\ActivityOptions;
use Temporal\Tests\Activity\SimpleActivity;
use Temporal\Workflow;
use Temporal\Workflow\SignalMethod;
use Temporal\Workflow\WorkflowMethod;
#[Workflow\WorkflowInterface]
class LoopWithSignalCoroutinesWorkflow
{
private array $values = [];
private array $result = [];
private $simple;
public function __construct()
{
$this->simple = Workflow::newActivityStub(
SimpleActivity::class,
ActivityOptions::new()->withStartToCloseTimeout(5)
);
}
#[SignalMethod]
public function addValue(
string $value
) {
$value = yield $this->simple->prefix('in signal ', $value);
$value = yield $this->simple->prefix('in signal 2 ', $value);
$this->values[] = $value;
}
#[WorkflowMethod(name: 'LoopWithSignalCoroutinesWorkflow')]
public function run(
int $count
) {
while (true) {
yield Workflow::await(fn() => $this->values !== []);
$value = array_shift($this->values);
// uppercases
$this->result[] = yield $this->simple->echo($value);
if (count($this->result) === $count) {
break;
}
}
asort($this->result);
return array_values($this->result);
}
}
|