Join 4,000+ others and never miss out on new tips, tutorials, and more.
4.x is outdated, please check the latest version 22.x
Latest version:
pecl install openswoole-22.1.2
<?php Swoole\Coroutine\WaitGroup->count()
Get the pending count of the wait group.
<?php
declare(strict_types=1);
use Swoole\Coroutine\WaitGroup;
Co\run(function() {
$wg = new WaitGroup();
go(function () use ($wg) {
$wg->add();
co::usleep(300000);
$wg->done();
});
go(function () use ($wg) {
$wg->add();
co::usleep(700000);
echo $wg->count();
$wg->done();
});
$wg->wait(1);
});