parallel-functions/examples/4-closure.php

15 lines
459 B
PHP
Raw Normal View History

2017-12-13 22:58:26 +01:00
<?php
require __DIR__ . '/../vendor/autoload.php';
use function Amp\ParallelFunctions\parallelMap;
2017-12-13 22:58:26 +01:00
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.
2022-02-02 23:04:43 +01:00
var_dump(wait(parallelMap([1, 2, 3], function ($time) {
sleep($time); // a blocking function call, might also do blocking I/O here
2017-12-13 22:58:26 +01:00
return $time * $time;
2017-12-13 23:48:03 +01:00
})));