Welcome toVigges Developer Community-Open, Learning,Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
774 views
in Technique[技术] by (71.8m points)

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
un(function () {
    while(true) {
        Coroutine::create(function () {
            // 业务1
        });
        
        Coroutine::create(function () {
            // 业务2
        });
    }
}); 

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

WaitGroup自己控制下就可以了


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to Vigges Developer Community for programmer and developer-Open, Learning and Share
...