Coroutine::resume

最后更新于:2022-04-02 06:26:03

# Coroutine::resume [TOC] 恢复某个协程,使其继续运行。 ~~~ function Swoole\Coroutine::resume(int $coroutineId); ~~~ * 参数`$coroutineId`为要恢复的协程`ID`,在协程内可以使用`Coroutine::getUid`获取到协程的`ID` * 当前协程处于挂起状态时,另外的协程中可以使用`resume`再次唤醒当前协程 ## 实例 ~~~ use Swoole\Coroutine as co; $id = go(function(){ $id = co::getUid(); echo "start coro $id\n"; co::suspend(); echo "resume coro $id @1\n"; co::suspend(); echo "resume coro $id @2\n"; }); echo "start to resume $id @1\n"; co::resume($id); echo "start to resume $id @2\n"; co::resume($id); echo "main\n"; --EXPECT-- start coro 1 start to resume 1 @1 resume coro 1 @1 start to resume 1 @2 resume coro 1 @2 main ~~~
';