Swoole\Coroutine\WaitGroup->add

Latest version: pecl install openswoole-4.11.1

Declaration

<?php Swoole\Coroutine\WaitGroup->add(int $count = 1)

Parameters

count

Increment the WaitGroup counter by the value.

Return

success

if success, it returns TRUE, otherwise it returns FALSE.

Description

Increment the WaitGroup counter, by default increment it by 1.

Example

<?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);
        $wg->done();
    });

    $wg->wait(1);
});
Last updated on March 31, 2022