Skip to content
This repository has been archived by the owner on Sep 1, 2020. It is now read-only.

Latest commit

 

History

History
36 lines (32 loc) · 801 Bytes

3.1.4 - Coroutine::resume.md

File metadata and controls

36 lines (32 loc) · 801 Bytes

Coroutine::resume

恢复某个协程,使其继续运行。

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