PHP code example of react-parallel / worker-pool

1. Go to this page and download the library: Download react-parallel/worker-pool library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

react-parallel / worker-pool example snippets




use Money\Money;
use React\EventLoop\Factory;
use ReactParallel\Factory as ParallelFactory;
use ReactParallel\Pool\Worker\Workers\ReturnWorkerFactory;
use ReactParallel\Pool\Worker\Workers\WorkObject;

ool->perform(new WorkObject(Money::EUR(512)))->always(function () use ($pool) {
    $pool->close();
})->done(function (Money $money) {
    echo $money->getAmount();
});

$loop->run();



declare(strict_types=1);

namespace ReactParallel\Pool\Worker\Workers;

use ReactParallel\Pool\Worker\Work\Worker as WorkerInterface;
use ReactParallel\Pool\Worker\Work\WorkerFactory;

final class ReturnWorkerFactory implements WorkerFactory
{
    public function construct(): WorkerInterface
    {
        return new ReturnWorker();
    }
}



declare(strict_types=1);

namespace ReactParallel\Pool\Worker\Workers;

use ReactParallel\Pool\Worker\Work as WorkContract;
use ReactParallel\Pool\Worker\Work\Worker as WorkerInterface;

final class ReturnWorker implements WorkerInterface
{
    public function perform(WorkContract $work): Result
    {
        return new Result($work->work());
    }
}