当设置 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
});
}
});
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…