Swoole 达到协程数量上限后,如何阻塞等待释放?

当设置 max_coroutine 为 10,当创建的协程达到最大数量10时,协程创建失败,业务不会执行,如何让其阻塞,让其等待其他协程释放后,再唤醒进行创建协程?

const MAX_COROUTINE = 10;

Runtime::enableCoroutine();
$s = microtime(true);
Co::set([
    'hook_flags' => SWOOLE_HOOK_ALL,
    'max_coroutine' => MAX_COROUTINE,
    'socket_timeout' => -1,
    'socket_connect_timeout' => -1,
]);
Co\run(function () {
    while(true) {
        Coroutine::create(function () {
            // 业务1
        });
        
        Coroutine::create(function () {
            // 业务2
        });
    }
}); 
阅读 4.5k
推荐问题