File tree Expand file tree Collapse file tree 1 file changed +49
-0
lines changed
Expand file tree Collapse file tree 1 file changed +49
-0
lines changed Original file line number Diff line number Diff line change 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
You can’t perform that action at this time.
0 commit comments