public function wait()
{
// $process = new \Symfony\Component\Process\Process;
$finished = false;
while (!$finished) {
foreach ($this->collection->all() as $n => $process) {
$p = $process->process;
$cb = $process->callback;
if (!$p->isStarted() && $this->getNbRunning() < $this->max) {
$p->start();
}
if ($p->isTerminated()) {
$cb($p->getOutput());
$this->collection->remove($n);
}
}
if ($this->getNbRunning() == 0) {
$finished = true;
}
gc_collect_cycles();
sleep(2);
}
}