Swoole Co-path blocking problem

< H2 > Synergetic path is blocked in swoole < / H2 >

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

Apr.20,2022

because the loop in $chan- > isEmpty () = true
while will not be blocked
because the $chan capacity defaults to 1
the second push blocks


Why did you quit immediately when you only ran one trip? @ seeker

$chan = new \Swoole\Coroutine\Channel();
function task1(\Swoole\Coroutine\Channel $chan) {
    Co::sleep(0.005);
    $chan->push([__METHOD__=>__LINE__]);
}
go("task1", $chan);
go(function () use ($chan){
    // isEmpty===true,
    while(!$chan->isEmpty()) {
        var_dump($chan->pop());
    }
});
MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1e84ba5-cfa.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1e84ba5-cfa.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?