mirror of
https://github.com/danog/parallel-functions.git
synced 2024-11-26 20:34:49 +01:00
Add example with many process pools, to test proper garbage collection
This commit is contained in:
parent
999ba8a00a
commit
37dbf46ae5
21
examples/5-many-pools.php
Normal file
21
examples/5-many-pools.php
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
require __DIR__ . '/../vendor/autoload.php';
|
||||||
|
|
||||||
|
use Amp\Parallel\Worker\DefaultPool;
|
||||||
|
use function Amp\ParallelFunctions\parallelMap;
|
||||||
|
use function Amp\Promise\wait;
|
||||||
|
|
||||||
|
// This pool uses 30 separate process pools in a row and processes 50 tasks for each.
|
||||||
|
// It demonstrates that new pools can be used without issues. For better efficiency,
|
||||||
|
// always use the same process pool, which can simply be the default pool.
|
||||||
|
|
||||||
|
for ($i = 0; $i < 30; $i++) {
|
||||||
|
$pool = new DefaultPool();
|
||||||
|
|
||||||
|
$promises = parallelMap(range(1, 50), function () {
|
||||||
|
return 2;
|
||||||
|
}, $pool);
|
||||||
|
|
||||||
|
$result = wait($promises);
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user