Esempio n. 1
0
 public function tick()
 {
     $currentTime = microtime(true);
     foreach ($this->timeouts as $index => $info) {
         if ($info[0] <= $currentTime) {
             $event = new Event('timeout', [], $this);
             $event->dispatch($info[1]);
             // remove from the queue
             unset($this->timeouts[$index]);
         }
     }
     foreach ($this->intervals as &$info) {
         if ($info[0] <= microtime(true)) {
             $event = new Event('interval', [], $this);
             $event->dispatch($info[1]);
             $info[0] = microtime(true) + $info[2];
         }
     }
     return $this;
 }
Esempio n. 2
0
 public function emit($eventName)
 {
     if (!isset($this->listeners[$eventName]) and !isset($this->listenersOnce[$eventName])) {
         // not sure about this
         return null;
     }
     $args = func_get_args();
     array_shift($args);
     $event = new Event($eventName, $args, $this);
     if (isset($this->listeners[$eventName])) {
         foreach ($this->listeners[$eventName] as $listener) {
             $event->dispatch($listener);
         }
     }
     if (isset($this->listenersOnce[$eventName])) {
         foreach ($this->listenersOnce[$eventName] as $key => $listener) {
             $event->dispatch($listener);
             unset($this->listenersOnce[$eventName][$key]);
         }
     }
     if ($this->eventDebug) {
         printf("%s %s %s", $event->name, $event->dispatchCount, json_encode($event->dispatchArgs));
     }
     return $event;
 }