Add example with many process pools, to test proper garbage collection

This commit is contained in:
Niklas Keller 2017-12-26 12:06:04 +01:00
parent 999ba8a00a
commit 37dbf46ae5

21
examples/5-many-pools.php Normal file
View 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);
}