demo.php:
Co::set([
"trace_flags" => SWOOLE_TRACE_CLOSE
]);
$chan = new \Swoole\Coroutine\Channel();
function task1(\Swoole\Coroutine\Channel $chan) {
Co::sleep(0.005);
$chan->push([__METHOD__=>__LINE__]);
}
function task2(\Swoole\Coroutine\Channel $chan) {
Co::sleep(0.005);
$chan->push([__METHOD__=>__LINE__]);
}
go("task1", $chan);
go("task2", $chan);
go(function () use ($chan){
while(!$chan->isEmpty()) {
var_dump($chan->pop());
}
});
phenomenon: the execution of php demo.php blocks for a long time