Beispiel #1
0
 /**
  * {@inheritdoc}
  */
 protected function activate(array $watchers)
 {
     foreach ($watchers as $watcher) {
         if (!isset($this->events[$id = $watcher->id])) {
             switch ($watcher->type) {
                 case Watcher::READABLE:
                     $this->events[$id] = $this->handle->io($watcher->value, \Ev::READ, $this->ioCallback, $watcher);
                     break;
                 case Watcher::WRITABLE:
                     $this->events[$id] = $this->handle->io($watcher->value, \Ev::WRITE, $this->ioCallback, $watcher);
                     break;
                 case Watcher::DELAY:
                 case Watcher::REPEAT:
                     $interval = $watcher->value / self::MILLISEC_PER_SEC;
                     $this->events[$id] = $this->handle->timer($interval, $watcher->type & Watcher::REPEAT ? $interval : 0, $this->timerCallback, $watcher);
                     break;
                 case Watcher::SIGNAL:
                     $this->events[$id] = $this->handle->signal($watcher->value, $this->signalCallback, $watcher);
                     break;
                 default:
                     throw new \DomainException("Unknown watcher type");
             }
         } else {
             $this->events[$id]->start();
         }
     }
 }
Beispiel #2
0
 /**
  * {@inheritdoc}
  */
 public function create()
 {
     if (EvLoop::supported()) {
         return new EvLoop();
     }
     return new NativeLoop();
 }