Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

当设置 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
        });
    }
}); 

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
1.3k views
Welcome To Ask or Share your Answers For Others

1 Answer

WaitGroup自己控制下就可以了


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...