/** * @param \Icicle\Loop\EvLoop $loop * @param int $eventType */ public function __construct(EvLoop $loop, int $eventType) { $this->loop = $loop->getEvLoop(); $this->type = $eventType; $this->socketCallback = function (\EvIO $event) { /** @var \Icicle\Loop\Watcher\Io $io */ $io = $event->data; $id = (int) $io->getResource(); if ($io->isPersistent()) { if (isset($this->timers[$id])) { $this->timers[$id]->again(); } } else { $event->stop(); if (isset($this->timers[$id])) { $this->timers[$id]->stop(); } } $io->call(false); }; $this->timerCallback = function (\EvTimer $event) { /** @var \Icicle\Loop\Watcher\Io $io */ $io = $event->data; $id = (int) $io->getResource(); $event->stop(); $this->events[$id]->stop(); $io->call(true); }; }
/** * @param \Icicle\Loop\EvLoop $loop */ public function __construct(EvLoop $loop) { $this->loop = $loop->getEvLoop(); $this->timers = new ObjectStorage(); $this->callback = function (\EvTimer $event) { /** @var \Icicle\Loop\Events\Timer $timer */ $timer = $event->data; if (!$timer->isPeriodic()) { $event->stop(); unset($this->timers[$timer]); } else { $event->again(); } $timer->call(); }; }