Esempio n. 1
0
 /**
  * Executes any pending timers. Returns the number of timers executed.
  *
  * @return int
  *
  * @internal
  */
 public function tick() : int
 {
     $count = 0;
     $time = microtime(true);
     while (!$this->queue->isEmpty()) {
         list($timer, $timeout) = $this->queue->top();
         if (!$this->timers->contains($timer) || $timeout !== $this->timers[$timer]) {
             $this->queue->extract();
             // Timer was removed from queue.
             continue;
         }
         if ($this->timers[$timer] > $time) {
             // Timer at top of queue has not expired.
             return $count;
         }
         // Remove and execute timer. Replace timer if persistent.
         $this->queue->extract();
         if ($timer->isPeriodic()) {
             $timeout = $time + $timer->getInterval();
             $this->queue->insert([$timer, $timeout], -$timeout);
             $this->timers[$timer] = $timeout;
         } else {
             $this->timers->detach($timer);
         }
         // Execute the timer.
         $timer->call();
         ++$count;
     }
     return $count;
 }
Esempio n. 2
0
 /**
  * {@inheritdoc}
  */
 public function clear()
 {
     for ($this->timers->rewind(); $this->timers->valid(); $this->timers->next()) {
         $this->timers->getInfo()->free();
     }
     $this->timers = new ObjectStorage();
 }
Esempio n. 3
0
 /**
  * {@inheritdoc}
  */
 public function tick()
 {
     if (!$this->queue->isEmpty()) {
         $immediate = $this->queue->shift();
         $this->immediates->detach($immediate);
         // Execute the immediate.
         $immediate->call();
         return true;
     }
     return false;
 }