/** * {@inheritdoc} */ protected function disableRepeatWatcher(TimerWatcher $watcher, bool $dispose = false) { if ($watcher->event === null) { return; } unset($this->timerWatchers[(int) $watcher->event]); if (\uv_is_active($watcher->event)) { \uv_timer_stop($watcher->event); } if ($dispose) { try { if ($this->dispatching) { $this->dispose->enqueue($watcher->event); } else { \uv_close($watcher->event); } } finally { $watcher->event = null; } } }
/** * {@inheritdoc} */ public function cancel(Io $io) { $id = (int) $io->getResource(); if (isset($this->sockets[$id], $this->polls[$id]) && $io === $this->sockets[$id] && \uv_is_active($this->polls[$id])) { \uv_poll_stop($this->polls[$id]); if (isset($this->timers[$id]) && \uv_is_active($this->timers[$id])) { \uv_timer_stop($this->timers[$id]); } } }
<?php $loop = uv_default_loop(); $timer = uv_timer_init(); $i = 0; uv_timer_start($timer, 1000, 1000, function ($stat) use(&$i, $timer, $loop) { echo "count: {$i}" . PHP_EOL; $i++; if ($i > 3) { uv_timer_stop($timer); uv_unref($timer); } }); uv_run(); echo "finished";
/** * {@inheritDoc} */ public function disable($watcherId) { if (!isset($this->watchers[$watcherId])) { return; } $watcher = $this->watchers[$watcherId]; if (!$watcher->isEnabled) { return; } $watcher->isEnabled = false; $this->keepAliveCount -= $watcher->keepAlive; switch ($watcher->type) { case Watcher::IO_READER: // fallthrough // fallthrough case Watcher::IO_WRITER: $this->disablePollFromWatcher($watcher); break; case Watcher::SIGNAL: \uv_signal_stop($watcher->uvHandle); break; case Watcher::IMMEDIATE: unset($this->immediates[$watcherId]); break; case Watcher::TIMER_ONCE: // fallthrough // fallthrough case Watcher::TIMER_REPEAT: \uv_timer_stop($watcher->uvHandle); break; default: throw new \RuntimeException("Unexpected Watcher type encountered"); } }
public function clearInterval($interval_id) { uv_timer_stop($interval_id); uv_unref($interval_id); }
/** * Stops the idler. * * @return Idle */ public function stop() { \uv_timer_stop($this->idler); return $this; }