Example #1
0
 /**
  * @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();
                         }
                     }
                 }
             }
         }
     }
 }
Example #2
0
 public function removeJob(Job $job)
 {
     $this->jobs->removeElement($job);
     return $this;
 }
Example #3
0
 /**
  * @return int
  */
 public function count()
 {
     return $this->jobs->count();
 }