parallel-functions/examples/4-closure.php
2022-02-02 23:04:43 +01:00

15 lines
459 B
PHP

<?php
require __DIR__ . '/../vendor/autoload.php';
use function Amp\ParallelFunctions\parallelMap;
use function Amp\Promise\wait;
// Parallel function execution is nice, but it's even better being able to use closures instead of having to write a
// function that has to be autoloadable.
var_dump(wait(parallelMap([1, 2, 3], function ($time) {
sleep($time); // a blocking function call, might also do blocking I/O here
return $time * $time;
})));