public function run() { if (empty($this->robots)) { throw new \RuntimeException("No robot instances have been added. Use RobotSwarm::add() method."); } do { // Refill only when pause is NOT requested if (!$this->pauseRequested) { foreach ($this->robots as $robot) { $this->refillRobot($robot); } } $queueNotEmptyBefore = $this->queue->count() > 0; // If queue is not empty, do socketPerform and store the result in variable $queueNotEmptyAfter = $queueNotEmptyBefore ? $this->queue->socketPerform() : false; if ($this->pauseRequested && $queueNotEmptyBefore && !$queueNotEmptyAfter) { $this->dispatch('queue.paused', new QueuePausedEvent($this)); $this->pauseRequested = false; } usleep($this->tickInterval); } while ($queueNotEmptyAfter || !$this->requestProviderEmpty); }
public function onTick() { if ($this->queue->count() > 0) { $this->queue->socketPerform(); } }