blob: 5f1af7669610be6e97a4cf9a2424e5570941c333 (
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
|
<?php
namespace Temporal\Tests\Workflow;
use React\Promise\Deferred;
use React\Promise\PromiseInterface;
use Temporal\Activity\ActivityOptions;
use Temporal\Workflow;
use Temporal\Workflow\WorkflowMethod;
use Temporal\Tests\Activity\SimpleActivity;
#[Workflow\WorkflowInterface]
class WorkflowWithSignalledSteps
{
#[WorkflowMethod(name: 'WorkflowWithSignalledSteps')]
public function handler()
{
$simple = Workflow::newActivityStub(
SimpleActivity::class,
ActivityOptions::new()->withStartToCloseTimeout(5)
);
$value = 0;
Workflow::registerQuery('value', function () use (&$value) {
return $value;
});
yield $this->promiseSignal('begin');
$value++;
yield $this->promiseSignal('next1');
$value++;
yield $this->promiseSignal('next2');
$value++;
return $value;
}
// is this correct?
private function promiseSignal(string $name): PromiseInterface
{
$signal = new Deferred();
Workflow::registerSignal($name, function ($value) use ($signal) {
$signal->resolve($value);
});
return $signal->promise();
}
}
|