Closed leocavalcante closed 3 years ago
<?php Swoole\Coroutine\map(array $list, callable $fn, float $timeout = -1): array
$fn
fn
list
Conceptually similar to batch() and parallel(), but behaves more like array_map(), each element will be mapped within a coroutine.
batch()
parallel()
array_map()
<?php declare(strict_types=1); use Swoole\Coroutine; use function Swoole\Coroutine\map; function fatorial(int $n): int { return array_product(range($n, 1)); } Coroutine\run(function () { $results = map([2, 3, 4], 'fatorial'); print_r($results); // 2 6 24 });
Declaration
Parameters
$fn
functionReturn
fn
to the correspondinglist
Description
Conceptually similar to
batch()
andparallel()
, but behaves more likearray_map()
, each element will be mapped within a coroutine.Example