<commit_before><?php

require dirname(dirname(__DIR__)) . '/vendor/autoload.php';

use React\ChildProcess\Process;
use React\EventLoop\Factory as EventLoopFactory;
use WyriHaximus\React\ChildProcess\Messenger\Messages\Factory as MessagesFactory;
use WyriHaximus\React\ChildProcess\Messenger\Messages\Payload;
use WyriHaximus\React\ChildProcess\Pool\CpuCoreCountFixedPool;

$loop = EventLoopFactory::create();

$poolClass = CpuCoreCountFixedPool::class;

$messenger = new $poolClass(new Process(''), $loop, [
    'processClassName' => 'WyriHaximus\React\ChildProcess\Messenger\ReturnChild',
]);

$i = 0;
for ($i = 0; $i < 100; $i++) {
    echo $i, PHP_EOL;

    $messenger->rpc(MessagesFactory::rpc('return', [
        'i' => $i,
        'time' => time(),
        'string' => str_pad('0', 1024 * 1024 * 5)
    ]))->then(function (Payload $payload) use ($messenger) {
        echo $payload['i'], PHP_EOL;
        echo $payload['time'], PHP_EOL;
        if ($payload['i'] == 99) {
            $messenger->terminate();
        }
    });
}

$loop->run();<commit_msg>Updated first example to new API<commit_after><?php

require dirname(dirname(__DIR__)) . '/vendor/autoload.php';

use React\EventLoop\Factory as EventLoopFactory;
use WyriHaximus\React\ChildProcess\Messenger\Messages\Factory as MessagesFactory;
use WyriHaximus\React\ChildProcess\Messenger\Messages\Payload;
use WyriHaximus\React\ChildProcess\Pool\Pool\Fixed;

$loop = EventLoopFactory::create();

$pool = Fixed::createFromClass('WyriHaximus\React\ChildProcess\Messenger\ReturnChild', $loop);

$i = 0;
for ($i = 0; $i < 100; $i++) {
    echo $i, PHP_EOL;

    $pool->rpc(MessagesFactory::rpc('return', [
        'i' => $i,
        'time' => time(),
        'string' => str_pad('0', 1024 * 1024 * 5)
    ]))->then(function (Payload $payload) use ($pool) {
        echo $payload['i'], PHP_EOL;
        echo $payload['time'], PHP_EOL;
        if ($payload['i'] == 99) {
            $pool->terminate();
        }
    });
}

$loop->run();
{'fraction_non_alphanumeric': 0.17552657973921765, 'fraction_numerical': 0.017051153460381142, 'mean_word_length': 3.795673076923077, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 18, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3285007', 'n_tokens_mistral': 730, 'n_tokens_neox': 686, 'n_words': 128}