Example

<?php

declare(ticks=1);

require_once __DIR__ . '/../../../vendor/autoload.php';

use vennv\vapm\System;
use vennv\vapm\AwaitGroup;
use vennv\vapm\CoroutineGen;

$tasks = 5000000;

System::time();

$awaitG = new AwaitGroup();
$awaitG->add($tasks);

$number = 0;

for ($i = 0; $i < $tasks; $i++) {
    CoroutineGen::runNonBlocking(
        function () use (&$awaitG, $i, &$number) {
            $number++;
            yield from $awaitG->done();
        }
    );
}

$awaitG->wait();
var_dump($number);
System::timeEnd();

Last updated