OpenSwoole\Core\Coroutine\WaitGroup->count

Latest version: pecl install openswoole-22.1.2 | composer require openswoole/core:22.1.5

Declaration

<?php OpenSwoole\Core\Coroutine\WaitGroup->count()

Parameters

Return

Description

Get the pending count of the wait group.

You have to install OpenSwoole core library with composer require openswoole/core to use this feature.

Example

<?php
declare(strict_types=1);

use OpenSwoole\Core\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);
});
Last updated on February 9, 2023