public function cancel() { $this->loop->cancelTimer($this->timer); }
<?php use React\EventLoop\Factory; use React\EventLoop\Timer\TimerInterface; use WyriHaximus\React\Inspector\InfoProvider; use WyriHaximus\React\Inspector\LoopDecorator; require 'vendor/autoload.php'; $loop = new LoopDecorator(Factory::create()); $info = new InfoProvider($loop); for ($i = 1; $i <= 3; $i++) { $loop->addTimer($i, function () { }); $loop->addPeriodicTimer(1.0E-5, function (TimerInterface $timer) use($loop) { if (mt_rand(0, 10000) == mt_rand(0, 10000)) { $loop->cancelTimer($timer); } }); $loop->nextTick(function () use($loop) { $loop->nextTick(function () { }); }); $loop->futureTick(function () use($loop) { $loop->futureTick(function () { }); }); } $loop->run(); var_export($info->getCounters());
protected function setupStreams(LoopDecorator $loop) { $loop->on('addReadStream', function ($stream) { $key = (int) $stream; $this->streamsRead[$key] = $stream; $this->streamsDuplex[$key] = $stream; $this->counters['streams']['read']['current'] = count($this->streamsRead); $this->counters['streams']['total']['current'] = count($this->streamsDuplex); $this->counters['streams']['read']['total']++; if (!isset($this->streamsWrite[$key])) { $this->counters['streams']['total']['total']++; } }); $loop->on('readStreamTick', function () { $this->counters['streams']['read']['ticks']++; $this->counters['streams']['total']['ticks']++; }); $loop->on('removeReadStream', function ($stream) { $key = (int) $stream; if (isset($this->streamsRead[$key])) { unset($this->streamsRead[$key]); } if (isset($this->streamsDuplex[$key]) && !isset($this->streamsWrite[$key])) { unset($this->streamsDuplex[$key]); } $this->counters['streams']['read']['current'] = count($this->streamsRead); $this->counters['streams']['total']['current'] = count($this->streamsDuplex); }); $loop->on('addWriteStream', function ($stream) { $key = (int) $stream; $this->streamsWrite[$key] = $stream; $this->streamsDuplex[$key] = $stream; $this->counters['streams']['write']['current'] = count($this->streamsWrite); $this->counters['streams']['total']['current'] = count($this->streamsDuplex); $this->counters['streams']['write']['total']++; if (!isset($this->streamsRead[$key])) { $this->counters['streams']['total']['total']++; } }); $loop->on('writeStreamTick', function () { $this->counters['streams']['write']['ticks']++; $this->counters['streams']['total']['ticks']++; }); $loop->on('removeWriteStream', function ($stream) { $key = (int) $stream; if (isset($this->streamsWrite[$key])) { unset($this->streamsWrite[$key]); } if (isset($this->streamsDuplex[$key]) && !isset($this->streamsRead[$key])) { unset($this->streamsDuplex[$key]); } $this->counters['streams']['write']['current'] = count($this->streamsWrite); $this->counters['streams']['total']['current'] = count($this->streamsDuplex); }); $loop->on('removeStream', function ($stream) { $key = (int) $stream; if (isset($this->streamsRead[$key])) { unset($this->streamsRead[$key]); } if (isset($this->streamsWrite[$key])) { unset($this->streamsWrite[$key]); } if (isset($this->streamsDuplex[$key])) { unset($this->streamsDuplex[$key]); } $this->counters['streams']['read']['current'] = count($this->streamsRead); $this->counters['streams']['write']['current'] = count($this->streamsWrite); $this->counters['streams']['total']['current'] = count($this->streamsDuplex); }); }