/** * Returns the global worker pool for the current context. * * @param PoolInterface|null $pool A worker pool instance. * * @return PoolInterface The global worker pool instance. */ function pool(PoolInterface $pool = null) { static $instance; if (null !== $pool) { $instance = $pool; } elseif (null === $instance) { $instance = new Pool(); } if (!$instance->isRunning()) { $instance->start(); } return $instance; }
public function startPool(Configuration $config) { $config->initialize(); $pool = new Pool($config); $pool->start(); $pool->join(); }
} /** * StagingData to hold data from StageOne */ class StagingData extends Stackable { public function run() { } } /* stage and data reference arrays */ $one = []; $two = []; $data = []; $pool = new Pool(8); $pool->start(); /* construct stage one */ while (count($one) < 10) { $staging = new StagingData(); /* maintain reference counts by storing return value in normal array in local scope */ $one[] = $pool->submit(new StageOne($staging)); /* maintain reference counts */ $data[] = $staging; } /* construct stage two */ while (count($one)) { /* find completed StageOne objects */ foreach ($one as $id => $job) { /* if done is set, the data from this StageOne can be used */ if ($job->done) { /* use each element of data to create new tasks for StageTwo */