Swoole\Coroutine\WaitGroup->__construct

Notice: ext-swoole is supported until v4.7.1, use ext-openswoole >= v4.7.1. Latest version: pecl install openswoole-4.9.1

Declaration

<?php
Swoole\Coroutine\WaitGroup->__construct()

Parameters

Return

Description

Create a new WaitGroup.

Example

<?php
declare(strict_types=1);

use Swoole\Coroutine\WaitGroup;

Co\run(function() {
    $wg = new WaitGroup();

    go(function () use ($wg) {
        $wg->add();
        co::sleep(0.3);
        $wg->done();
    });

    go(function () use ($wg) {
        $wg->add();
        co::sleep(0.7);
        $wg->done();
    });

    $wg->wait(1);
});