Completed
Push — master ( 785bde...8b4d11 )
by Freek
01:29
created

src/macros/parallelMap.php (1 issue)

Labels
Severity

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
3
use Amp\Parallel\Worker\Pool;
4
use function Amp\Promise\wait;
5
use Illuminate\Support\Collection;
6
use Amp\Parallel\Worker\DefaultPool;
7
use function Amp\ParallelFunctions\parallelMap;
8
9
/*
10
 * Idential to map but each item will be processed in parallel.
11
 *
12
 * This function requires the installation of amphp/parallel-functions
13
 *
14
 * @param callable $callback
15
 *
16
 * @return \Illuminate\Support\Collection
17
 */
18
Collection::macro('parallelMap', function (callable $callback, $workers = null): Collection {
19
    $pool = null;
20
21
    if ($workers instanceof Pool) {
22
        $pool = $workers;
23
    }
24
25
    if (is_int($workers)) {
26
        $pool = new DefaultPool($workers);
27
    }
28
29
    $promises = parallelMap($this->items, $callback, $pool);
0 ignored issues
show
The variable $this does not exist. Did you forget to declare it?

This check marks access to variables or properties that have not been declared yet. While PHP has no explicit notion of declaring a variable, accessing it before a value is assigned to it is most likely a bug.

Loading history...
30
31
    return new static(wait($promises));
32
});
33