Skip to content

Commit 05c447e

Browse files
committed
+ add 035-scope_self_cancellation.phpt
1 parent c44e66b commit 05c447e

File tree

1 file changed

+49
-0
lines changed

1 file changed

+49
-0
lines changed
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
--TEST--
2+
Scope: Coroutine cancelling its own scope
3+
--FILE--
4+
<?php
5+
6+
use function Async\spawn;
7+
use function Async\suspend;
8+
use function Async\await;
9+
10+
echo "start\n";
11+
12+
$scope = new \Async\Scope()->asNotSafely();
13+
14+
$self_cancelling = $scope->spawn(function() use ($scope) {
15+
echo "coroutine started\n";
16+
suspend(); // Let it start properly
17+
18+
echo "coroutine cancelling its own scope\n";
19+
$scope->cancel(new \Async\CancellationError("Self-cancellation"));
20+
echo "coroutine end\n";
21+
});
22+
23+
echo "spawned coroutine\n";
24+
25+
// Let coroutine start and cancel scope
26+
try {
27+
await($self_cancelling);
28+
} catch (\Async\CancellationError $e) {
29+
echo "caught cancellation in main\n";
30+
}
31+
32+
echo "checking final state\n";
33+
echo "scope cancelled: " . ($scope->isCancelled() ? "true" : "false") . "\n";
34+
echo "coroutine cancelled: " . ($self_cancelling->isCancelled() ? "true" : "false") . "\n";
35+
36+
echo "end\n";
37+
38+
?>
39+
--EXPECT--
40+
start
41+
spawned coroutine
42+
coroutine started
43+
coroutine cancelling its own scope
44+
coroutine end
45+
caught cancellation in main
46+
checking final state
47+
scope cancelled: true
48+
coroutine cancelled: true
49+
end

0 commit comments

Comments
 (0)