/** * @throws \Karzer\Exception\RuntimeException * @return Job[]|bool */ public function run() { $this->fillPool(); while (!$this->pool->isEmpty()) { $r = $this->pool->getStreams(); $w = array(); $x = array(); if (count($r) > 0) { $result = stream_select($r, $w, $x, null, $this->timeout); if (false === $result) { throw new RuntimeException('Stream select failed'); } elseif (0 === $result) { continue; } foreach ($r as $stream) { foreach ($this->pool as $job) { if ($job->hasStream($stream)) { $job->getStream($stream)->read(); if ($job->isClosed()) { $this->stopJob($job); if ($job->getResult()->shouldStop()) { break 3; } $this->fillPool(); } } } } } } }
public function removeJob(Job $job) { $this->jobs->removeElement($job); return $this; }
/** * @return int */ public function count() { return $this->jobs->count(); }