parallel-functions/examples/1-simple-function.php
2018-10-28 10:29:02 -05:00

17 lines
524 B
PHP

<?php
require __DIR__ . '/../vendor/autoload.php';
use function Amp\ParallelFunctions\parallelMap;
use function Amp\Promise\wait;
$start = \microtime(true);
// sleep() is executed in child processes, the results are sent back to the parent.
//
// All communication is non-blocking and can be used in an event loop. Amp\Promise\wait() can be used to use the library
// in a traditional synchronous environment.
wait(parallelMap([1, 2, 3], 'sleep'));
print 'Took ' . (\microtime(true) - $start) . ' seconds.' . \PHP_EOL;