Example #1
0
 public function add(TimerInterface $timer)
 {
     $interval = $timer->getInterval();
     $scheduledAt = $interval + $this->getTime();
     $this->timers->attach($timer, $scheduledAt);
     $this->scheduler->insert($timer, -$scheduledAt);
 }
Example #2
0
 /**
  * {@inheritdoc}
  */
 public function start(TimerInterface $timer)
 {
     if (!isset($this->timers[$timer])) {
         $interval = $timer->getInterval();
         $event = $this->loop->timer($interval, $timer->isPeriodic() ? $interval : 0, $this->callback, $timer);
         $this->timers[$timer] = $event;
     }
 }
 /**
  * @param TimerInterface $timer
  * @return $this
  * @throws \InvalidArgumentException
  */
 public function add(TimerInterface $timer)
 {
     $interval = $timer->getInterval();
     if ($interval < $this->getPrecision()) {
         throw new InvalidArgumentException('Timer events do not support sub-millisecond timeouts.');
     }
     $scheduledAt = $interval + $this->getTime();
     $this->timers->attach($timer, $scheduledAt);
     $this->scheduler->insert($timer, -$scheduledAt);
     return $this;
 }
Example #4
0
 /**
  * {@inheritdoc}
  */
 public function start(TimerInterface $timer)
 {
     $flags = Event::TIMEOUT;
     if ($timer->isPeriodic()) {
         $flags |= Event::PERSIST;
     }
     $event = new Event($this->base, -1, $flags, $this->callback, $timer);
     $this->timers[$timer] = $event;
     $event->add($timer->getInterval());
 }
Example #5
0
 /**
  * {@inheritdoc}
  */
 public function start(TimerInterface $timer)
 {
     if (!isset($this->timers[$timer])) {
         $handle = \uv_timer_init($this->loopHandle);
         $interval = $timer->getInterval() * self::MILLISEC_PER_SEC;
         \uv_timer_start($handle, $interval, $timer->isPeriodic() ? $interval : 0, $this->callback);
         $this->timers[$timer] = $handle;
         $this->handles[(int) $handle] = $timer;
     }
 }