blob: e2e43efaa70cc7becd47f87c6913081860dcd4bf (
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
56
57
|
<?php
namespace Temporal\Tests\Workflow;
use React\Promise\Deferred;
use Temporal\Workflow;
use Temporal\Workflow\WorkflowMethod;
#[Workflow\WorkflowInterface]
class CancelSignalledChildWorkflow
{
private array $status = [];
#[Workflow\QueryMethod(name: 'getStatus')]
public function getStatus(): array
{
return $this->status;
}
#[WorkflowMethod(name: 'CancelSignalledChildWorkflow')]
public function handler()
{
// typed stub
$simple = Workflow::newChildWorkflowStub(SimpleSignalledWorkflow::class);
$waitSignalled = new Deferred();
$this->status[] = 'start';
// start execution
$scope = Workflow::newCancellationScope(
function () use ($simple, $waitSignalled) {
$call = $simple->handler();
$this->status[] = 'child started';
yield $simple->add(8);
$this->status[] = 'child signalled';
$waitSignalled->resolve();
return yield $call;
}
);
// only cancel scope when signal dispatched
yield $waitSignalled;
$scope->cancel();
$this->status[] = 'scope cancelled';
try {
return yield $scope;
} catch (\Throwable $e) {
$this->status[] = 'process done';
return 'cancelled ok';
}
}
}
|