File tree Expand file tree Collapse file tree 1 file changed +48
-0
lines changed
Expand file tree Collapse file tree 1 file changed +48
-0
lines changed Original file line number Diff line number Diff line change 1+ --TEST--
2+ Fiber::getCoroutine() method
3+ --FILE--
4+ <?php
5+
6+ use function Async \spawn ;
7+ use function Async \await ;
8+
9+ // Test with coroutine
10+ $ c = spawn (function () {
11+ $ f = new Fiber (function () {
12+ Fiber::suspend ();
13+ });
14+
15+ $ f ->start ();
16+
17+ $ coro = $ f ->getCoroutine ();
18+ echo "Has coroutine: " . ($ coro !== null ? "yes " : "no " ) . "\n" ;
19+ echo "Coroutine ID: " . $ coro ->getId () . "\n" ;
20+ echo "Is started: " . ($ coro ->isStarted () ? "yes " : "no " ) . "\n" ;
21+ echo "Is suspended: " . ($ coro ->isSuspended () ? "yes " : "no " ) . "\n" ;
22+
23+ $ f ->resume ();
24+ });
25+
26+ await ($ c );
27+
28+ // Test without coroutine (regular fiber)
29+ $ f = new Fiber (function () {
30+ Fiber::suspend ();
31+ });
32+
33+ $ f ->start ();
34+
35+ $ coro = $ f ->getCoroutine ();
36+ echo "Regular fiber coroutine: " . ($ coro === null ? "null " : "not-null " ) . "\n" ;
37+
38+ $ f ->resume ();
39+
40+ echo "OK \n" ;
41+ ?>
42+ --EXPECT--
43+ Has coroutine: yes
44+ Coroutine ID: 2
45+ Is started: yes
46+ Is suspended: yes
47+ Regular fiber coroutine: null
48+ OK
You can’t perform that action at this time.
0 commit comments