From 4455a3be9426beb1bb0519cfa7c6529cbccc8ffd Mon Sep 17 00:00:00 2001 From: Mark Kimsal Date: Sat, 21 Mar 2015 08:54:53 -0400 Subject: [PATCH 01/17] Add loop driver for pecl libev extension. The existing libev driver seems to function only with a non-official, out of date libev extension for PHP. This PeclEvLoop class is a very similar clone of the LibEvLoop library but for the officially documented libev extension. Changes are mostly to constants and function parameter order. --- src/Factory.php | 2 + src/PeclEvLoop.php | 217 +++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 219 insertions(+) create mode 100644 src/PeclEvLoop.php diff --git a/src/Factory.php b/src/Factory.php index 9a481e35..5e49f832 100644 --- a/src/Factory.php +++ b/src/Factory.php @@ -11,6 +11,8 @@ public static function create() return new LibEventLoop(); } elseif (class_exists('libev\EventLoop', false)) { return new LibEvLoop; + } elseif (class_exists('EvLoop', false)) { + return new PeclEvLoop; } elseif (class_exists('EventBase', false)) { return new ExtEventLoop; } diff --git a/src/PeclEvLoop.php b/src/PeclEvLoop.php new file mode 100644 index 00000000..56251013 --- /dev/null +++ b/src/PeclEvLoop.php @@ -0,0 +1,217 @@ +loop = EvLoop::defaultLoop(); + $this->nextTickQueue = new NextTickQueue($this); + $this->futureTickQueue = new FutureTickQueue($this); + $this->timerEvents = new SplObjectStorage(); + } + + /** + * {@inheritdoc} + */ + public function addReadStream($stream, callable $listener) + { + $callback = function () use ($stream, $listener) { + call_user_func($listener, $stream, $this); + }; + + $event = $this->loop->io($stream, Ev::READ, $callback); + + $this->readEvents[(int) $stream] = $event; + } + + /** + * {@inheritdoc} + */ + public function addWriteStream($stream, callable $listener) + { + $callback = function () use ($stream, $listener) { + call_user_func($listener, $stream, $this); + }; + + $event = $this->loop->io($stream, Ev::WRITE, $callback); + + $this->writeEvents[(int) $stream] = $event; + } + + /** + * {@inheritdoc} + */ + public function removeReadStream($stream) + { + $key = (int) $stream; + + if (isset($this->readEvents[$key])) { + $this->readEvents[$key]->stop(); + unset($this->readEvents[$key]); + } + } + + /** + * {@inheritdoc} + */ + public function removeWriteStream($stream) + { + $key = (int) $stream; + + if (isset($this->writeEvents[$key])) { + $this->writeEvents[$key]->stop(); + unset($this->writeEvents[$key]); + } + } + + /** + * {@inheritdoc} + */ + public function removeStream($stream) + { + $this->removeReadStream($stream); + $this->removeWriteStream($stream); + } + + /** + * {@inheritdoc} + */ + public function addTimer($interval, callable $callback) + { + $timer = new Timer($this, $interval, $callback, false); + + $callback = function () use ($timer) { + call_user_func($timer->getCallback(), $timer); + + if ($this->isTimerActive($timer)) { + $this->cancelTimer($timer); + } + }; + + $event = $this->loop->timer($timer->getInterval(), 0.0, $callback); + $this->timerEvents->attach($timer, $event); + + return $timer; + } + + /** + * {@inheritdoc} + */ + public function addPeriodicTimer($interval, callable $callback) + { + $timer = new Timer($this, $interval, $callback, true); + + $callback = function () use ($timer) { + call_user_func($timer->getCallback(), $timer); + }; + + //reschedule callback should be NULL to utilize $offset and $interval params + $event = $this->loop->periodic($interval, $interval, NULL, $callback); + $this->timerEvents->attach($timer, $event); + + return $timer; + } + + /** + * {@inheritdoc} + */ + public function cancelTimer(TimerInterface $timer) + { + if (isset($this->timerEvents[$timer])) { + $event = $this->timerEvents->get($timer); + $event->stop(); + $this->timerEvents->detach($timer); + } + } + + /** + * {@inheritdoc} + */ + public function isTimerActive(TimerInterface $timer) + { + return $this->timerEvents->contains($timer); + } + + /** + * {@inheritdoc} + */ + public function nextTick(callable $listener) + { + $this->nextTickQueue->add($listener); + } + + /** + * {@inheritdoc} + */ + public function futureTick(callable $listener) + { + $this->futureTickQueue->add($listener); + } + + /** + * {@inheritdoc} + */ + public function tick() + { + $this->nextTickQueue->tick(); + + $this->futureTickQueue->tick(); + + $this->loop->run(Ev::RUN_ONCE | Ev::RUN_NOWAIT); + } + + /** + * {@inheritdoc} + */ + public function run() + { + $this->running = true; + + while ($this->running) { + $this->nextTickQueue->tick(); + + $this->futureTickQueue->tick(); + + $flags = Ev::RUN_ONCE; + if (!$this->running || !$this->nextTickQueue->isEmpty() || !$this->futureTickQueue->isEmpty()) { + $flags |= Ev::RUN_NOWAIT; + } elseif (!$this->readEvents && !$this->writeEvents && !$this->timerEvents->count()) { + break; + } + + $this->loop->run($flags); + } + } + + /** + * {@inheritdoc} + */ + public function stop() + { + $this->running = false; + } +} From 051a4a34449b4c5ddccf2132a9a61fda92ad54f4 Mon Sep 17 00:00:00 2001 From: Mark Kimsal Date: Sat, 21 Mar 2015 09:29:09 -0400 Subject: [PATCH 02/17] Document new driver. --- README.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/README.md b/README.md index 4e4ee3d0..f9fb9e76 100644 --- a/README.md +++ b/README.md @@ -106,6 +106,10 @@ In addition to the interface there are the following implementations provided: ([github](https://github.com/m4rw3r/php-libev)). It supports the same backends as libevent. +* `PeclEvLoop`: This uses the `libev` pecl extension that is documented on + ([php.net](http://php.net/manual/en/book.ev.php)). See + ([bitbucket](https://bitbucket.org/osmanov/pecl-ev/overview)) for source. + * `ExtEventLoop`: This uses the `event` pecl extension. It supports the same backends as libevent. From 0b375f70ec4a4a8c780b4e05867bafa44707de49 Mon Sep 17 00:00:00 2001 From: Ivan Kalita Date: Sat, 8 Apr 2017 17:04:32 +0300 Subject: [PATCH 03/17] Replace "EvLoop::defaultLoop()" with "new EvLoop()". --- src/PeclEvLoop.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/PeclEvLoop.php b/src/PeclEvLoop.php index 56251013..405455d4 100644 --- a/src/PeclEvLoop.php +++ b/src/PeclEvLoop.php @@ -28,7 +28,7 @@ class PeclEvLoop implements LoopInterface public function __construct() { - $this->loop = EvLoop::defaultLoop(); + $this->loop = new EvLoop(); $this->nextTickQueue = new NextTickQueue($this); $this->futureTickQueue = new FutureTickQueue($this); $this->timerEvents = new SplObjectStorage(); From 3391da527a29f3bad00bd4165e2086fcd8a20628 Mon Sep 17 00:00:00 2001 From: Ivan Kalita Date: Sat, 8 Apr 2017 17:05:50 +0300 Subject: [PATCH 04/17] Fix PeclEvLoop SplObjectStorage item retrieving method. --- src/PeclEvLoop.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/PeclEvLoop.php b/src/PeclEvLoop.php index 405455d4..f03c5f51 100644 --- a/src/PeclEvLoop.php +++ b/src/PeclEvLoop.php @@ -142,7 +142,7 @@ public function addPeriodicTimer($interval, callable $callback) public function cancelTimer(TimerInterface $timer) { if (isset($this->timerEvents[$timer])) { - $event = $this->timerEvents->get($timer); + $event = $this->timerEvents[$timer]; $event->stop(); $this->timerEvents->detach($timer); } From 0e56b44e90b591c2c039917aeb931e01f58085ab Mon Sep 17 00:00:00 2001 From: Ivan Kalita Date: Sat, 8 Apr 2017 17:47:43 +0300 Subject: [PATCH 05/17] Remove unnecessary "use" statements from PeclEvLoop. --- src/PeclEvLoop.php | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/PeclEvLoop.php b/src/PeclEvLoop.php index f03c5f51..03d62e66 100644 --- a/src/PeclEvLoop.php +++ b/src/PeclEvLoop.php @@ -4,9 +4,6 @@ use Ev; use EvLoop; -use EvIo; -use EvTimer; -use EvPeriodic; use React\EventLoop\Tick\FutureTickQueue; use React\EventLoop\Tick\NextTickQueue; use React\EventLoop\Timer\Timer; From 316e6a9ce07f5803a1c4f2ab948bcbc01544d310 Mon Sep 17 00:00:00 2001 From: Ivan Kalita Date: Sat, 8 Apr 2017 17:56:59 +0300 Subject: [PATCH 06/17] Remove nextTickQueue from PeclEvLoop. --- src/PeclEvLoop.php | 17 +---------------- 1 file changed, 1 insertion(+), 16 deletions(-) diff --git a/src/PeclEvLoop.php b/src/PeclEvLoop.php index 03d62e66..4c8e60f4 100644 --- a/src/PeclEvLoop.php +++ b/src/PeclEvLoop.php @@ -5,7 +5,6 @@ use Ev; use EvLoop; use React\EventLoop\Tick\FutureTickQueue; -use React\EventLoop\Tick\NextTickQueue; use React\EventLoop\Timer\Timer; use React\EventLoop\Timer\TimerInterface; use SplObjectStorage; @@ -16,7 +15,6 @@ class PeclEvLoop implements LoopInterface { private $loop; - private $nextTickQueue; private $futureTickQueue; private $timerEvents; private $readEvents = []; @@ -26,7 +24,6 @@ class PeclEvLoop implements LoopInterface public function __construct() { $this->loop = new EvLoop(); - $this->nextTickQueue = new NextTickQueue($this); $this->futureTickQueue = new FutureTickQueue($this); $this->timerEvents = new SplObjectStorage(); } @@ -153,14 +150,6 @@ public function isTimerActive(TimerInterface $timer) return $this->timerEvents->contains($timer); } - /** - * {@inheritdoc} - */ - public function nextTick(callable $listener) - { - $this->nextTickQueue->add($listener); - } - /** * {@inheritdoc} */ @@ -174,8 +163,6 @@ public function futureTick(callable $listener) */ public function tick() { - $this->nextTickQueue->tick(); - $this->futureTickQueue->tick(); $this->loop->run(Ev::RUN_ONCE | Ev::RUN_NOWAIT); @@ -189,12 +176,10 @@ public function run() $this->running = true; while ($this->running) { - $this->nextTickQueue->tick(); - $this->futureTickQueue->tick(); $flags = Ev::RUN_ONCE; - if (!$this->running || !$this->nextTickQueue->isEmpty() || !$this->futureTickQueue->isEmpty()) { + if (!$this->running || !$this->futureTickQueue->isEmpty()) { $flags |= Ev::RUN_NOWAIT; } elseif (!$this->readEvents && !$this->writeEvents && !$this->timerEvents->count()) { break; From 4c70da0e8a21c17257eb5a0bc8903adc4cbbd69c Mon Sep 17 00:00:00 2001 From: Ivan Kalita Date: Sat, 8 Apr 2017 18:02:22 +0300 Subject: [PATCH 07/17] Rename PeclEvLoop private members in StreamSelectLoop way. --- src/PeclEvLoop.php | 38 +++++++++++++++++++------------------- 1 file changed, 19 insertions(+), 19 deletions(-) diff --git a/src/PeclEvLoop.php b/src/PeclEvLoop.php index 4c8e60f4..faa9fcdb 100644 --- a/src/PeclEvLoop.php +++ b/src/PeclEvLoop.php @@ -16,16 +16,16 @@ class PeclEvLoop implements LoopInterface { private $loop; private $futureTickQueue; - private $timerEvents; - private $readEvents = []; - private $writeEvents = []; + private $timers; + private $readStreams = []; + private $writeStreams = []; private $running; public function __construct() { $this->loop = new EvLoop(); $this->futureTickQueue = new FutureTickQueue($this); - $this->timerEvents = new SplObjectStorage(); + $this->timers = new SplObjectStorage(); } /** @@ -39,7 +39,7 @@ public function addReadStream($stream, callable $listener) $event = $this->loop->io($stream, Ev::READ, $callback); - $this->readEvents[(int) $stream] = $event; + $this->readStreams[(int) $stream] = $event; } /** @@ -53,7 +53,7 @@ public function addWriteStream($stream, callable $listener) $event = $this->loop->io($stream, Ev::WRITE, $callback); - $this->writeEvents[(int) $stream] = $event; + $this->writeStreams[(int) $stream] = $event; } /** @@ -63,9 +63,9 @@ public function removeReadStream($stream) { $key = (int) $stream; - if (isset($this->readEvents[$key])) { - $this->readEvents[$key]->stop(); - unset($this->readEvents[$key]); + if (isset($this->readStreams[$key])) { + $this->readStreams[$key]->stop(); + unset($this->readStreams[$key]); } } @@ -76,9 +76,9 @@ public function removeWriteStream($stream) { $key = (int) $stream; - if (isset($this->writeEvents[$key])) { - $this->writeEvents[$key]->stop(); - unset($this->writeEvents[$key]); + if (isset($this->writeStreams[$key])) { + $this->writeStreams[$key]->stop(); + unset($this->writeStreams[$key]); } } @@ -107,7 +107,7 @@ public function addTimer($interval, callable $callback) }; $event = $this->loop->timer($timer->getInterval(), 0.0, $callback); - $this->timerEvents->attach($timer, $event); + $this->timers->attach($timer, $event); return $timer; } @@ -125,7 +125,7 @@ public function addPeriodicTimer($interval, callable $callback) //reschedule callback should be NULL to utilize $offset and $interval params $event = $this->loop->periodic($interval, $interval, NULL, $callback); - $this->timerEvents->attach($timer, $event); + $this->timers->attach($timer, $event); return $timer; } @@ -135,10 +135,10 @@ public function addPeriodicTimer($interval, callable $callback) */ public function cancelTimer(TimerInterface $timer) { - if (isset($this->timerEvents[$timer])) { - $event = $this->timerEvents[$timer]; + if (isset($this->timers[$timer])) { + $event = $this->timers[$timer]; $event->stop(); - $this->timerEvents->detach($timer); + $this->timers->detach($timer); } } @@ -147,7 +147,7 @@ public function cancelTimer(TimerInterface $timer) */ public function isTimerActive(TimerInterface $timer) { - return $this->timerEvents->contains($timer); + return $this->timers->contains($timer); } /** @@ -181,7 +181,7 @@ public function run() $flags = Ev::RUN_ONCE; if (!$this->running || !$this->futureTickQueue->isEmpty()) { $flags |= Ev::RUN_NOWAIT; - } elseif (!$this->readEvents && !$this->writeEvents && !$this->timerEvents->count()) { + } elseif (!$this->readStreams && !$this->writeStreams && !$this->timers->count()) { break; } From 3ae18290db297fd988488e6c8bdb41ddcde5f14e Mon Sep 17 00:00:00 2001 From: Ivan Kalita Date: Sat, 8 Apr 2017 18:12:08 +0300 Subject: [PATCH 08/17] Prevent PeclEvLoop from updating existing streams callbacks. --- src/PeclEvLoop.php | 34 +++++++++++++++++++++++++--------- 1 file changed, 25 insertions(+), 9 deletions(-) diff --git a/src/PeclEvLoop.php b/src/PeclEvLoop.php index faa9fcdb..37b541f6 100644 --- a/src/PeclEvLoop.php +++ b/src/PeclEvLoop.php @@ -33,13 +33,27 @@ public function __construct() */ public function addReadStream($stream, callable $listener) { - $callback = function () use ($stream, $listener) { - call_user_func($listener, $stream, $this); - }; + $key = (int) $stream; + if (isset($this->readStreams[$key])) { + return; + } + + $callback = $this->getStreamListenerClosure($stream, $listener); $event = $this->loop->io($stream, Ev::READ, $callback); + $this->readStreams[$key] = $event; + } - $this->readStreams[(int) $stream] = $event; + /** + * @param resource $stream + * @param callable $listener + * + * @return \Closure + */ + private function getStreamListenerClosure($stream, callable $listener) { + return function () use ($stream, $listener) { + call_user_func($listener, $stream, $this); + }; } /** @@ -47,13 +61,15 @@ public function addReadStream($stream, callable $listener) */ public function addWriteStream($stream, callable $listener) { - $callback = function () use ($stream, $listener) { - call_user_func($listener, $stream, $this); - }; + $key = (int) $stream; - $event = $this->loop->io($stream, Ev::WRITE, $callback); + if (isset($this->writeStreams[$key])) { + return; + } - $this->writeStreams[(int) $stream] = $event; + $callback = $this->getStreamListenerClosure($stream, $listener); + $event = $this->loop->io($stream, Ev::WRITE, $callback); + $this->writeStreams[$key] = $event; } /** From 52e5e2eefb5583f3c494429271894577146638da Mon Sep 17 00:00:00 2001 From: Ivan Kalita Date: Sat, 8 Apr 2017 18:23:30 +0300 Subject: [PATCH 09/17] Add early returns in PeclEvLoop removeReadStream, removeWriteStream and cancelTimer. --- src/PeclEvLoop.php | 26 ++++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/src/PeclEvLoop.php b/src/PeclEvLoop.php index 37b541f6..729a2e80 100644 --- a/src/PeclEvLoop.php +++ b/src/PeclEvLoop.php @@ -79,10 +79,12 @@ public function removeReadStream($stream) { $key = (int) $stream; - if (isset($this->readStreams[$key])) { - $this->readStreams[$key]->stop(); - unset($this->readStreams[$key]); + if (!isset($this->readStreams[$key])) { + return; } + + $this->readStreams[$key]->stop(); + unset($this->readStreams[$key]); } /** @@ -92,10 +94,12 @@ public function removeWriteStream($stream) { $key = (int) $stream; - if (isset($this->writeStreams[$key])) { - $this->writeStreams[$key]->stop(); - unset($this->writeStreams[$key]); + if (!isset($this->writeStreams[$key])) { + return; } + + $this->writeStreams[$key]->stop(); + unset($this->writeStreams[$key]); } /** @@ -151,11 +155,13 @@ public function addPeriodicTimer($interval, callable $callback) */ public function cancelTimer(TimerInterface $timer) { - if (isset($this->timers[$timer])) { - $event = $this->timers[$timer]; - $event->stop(); - $this->timers->detach($timer); + if (!isset($this->timers[$timer])) { + return; } + + $event = $this->timers[$timer]; + $event->stop(); + $this->timers->detach($timer); } /** From 5392032f2891e624d90a4a4970f65b171b589f77 Mon Sep 17 00:00:00 2001 From: Ivan Kalita Date: Sat, 8 Apr 2017 18:36:09 +0300 Subject: [PATCH 10/17] Make PeclEvLoop::run more verbose. --- src/PeclEvLoop.php | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/PeclEvLoop.php b/src/PeclEvLoop.php index 729a2e80..042074f7 100644 --- a/src/PeclEvLoop.php +++ b/src/PeclEvLoop.php @@ -200,10 +200,14 @@ public function run() while ($this->running) { $this->futureTickQueue->tick(); + $hasPendingCallbacks = !$this->futureTickQueue->isEmpty(); + $wasJustStopped = !$this->running; + $nothingLeftToDo = !$this->readStreams && !$this->writeStreams && !$this->timers->count(); + $flags = Ev::RUN_ONCE; - if (!$this->running || !$this->futureTickQueue->isEmpty()) { + if ($wasJustStopped || $hasPendingCallbacks) { $flags |= Ev::RUN_NOWAIT; - } elseif (!$this->readStreams && !$this->writeStreams && !$this->timers->count()) { + } elseif ($nothingLeftToDo) { break; } From 45b7ab077287e4b9c159f1a5f7b6233e7f8af265 Mon Sep 17 00:00:00 2001 From: Ivan Kalita Date: Sat, 8 Apr 2017 21:35:55 +0300 Subject: [PATCH 11/17] Add PeclEvLoop::__destruct() to prevent SEGFAULT. --- src/PeclEvLoop.php | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/PeclEvLoop.php b/src/PeclEvLoop.php index 042074f7..69d51548 100644 --- a/src/PeclEvLoop.php +++ b/src/PeclEvLoop.php @@ -222,4 +222,20 @@ public function stop() { $this->running = false; } + + public function __destruct() + { + /** @var TimerInterface $timer */ + foreach($this->timers as $timer) { + $this->cancelTimer($timer); + } + + foreach($this->readStreams as $key => $stream) { + $this->removeReadStream($key); + } + + foreach($this->writeStreams as $key => $stream) { + $this->removeWriteStream($key); + } + } } From 42bc95d4f0f4f336bf7b4600d0a4f417068c496d Mon Sep 17 00:00:00 2001 From: Ivan Kalita Date: Tue, 18 Apr 2017 19:42:32 +0300 Subject: [PATCH 12/17] Remove unnecessary PeclEvLoop::tick(). --- src/PeclEvLoop.php | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/src/PeclEvLoop.php b/src/PeclEvLoop.php index 69d51548..c11d31d1 100644 --- a/src/PeclEvLoop.php +++ b/src/PeclEvLoop.php @@ -180,16 +180,6 @@ public function futureTick(callable $listener) $this->futureTickQueue->add($listener); } - /** - * {@inheritdoc} - */ - public function tick() - { - $this->futureTickQueue->tick(); - - $this->loop->run(Ev::RUN_ONCE | Ev::RUN_NOWAIT); - } - /** * {@inheritdoc} */ From dac7c41ff85787ea32e920fa9623cc17d16eba95 Mon Sep 17 00:00:00 2001 From: Ivan Kalita Date: Fri, 21 Apr 2017 12:06:46 +0300 Subject: [PATCH 13/17] Remove unnecessary "@inheritdoc" from PeclEvLoop. --- src/PeclEvLoop.php | 36 ------------------------------------ 1 file changed, 36 deletions(-) diff --git a/src/PeclEvLoop.php b/src/PeclEvLoop.php index c11d31d1..d1d57102 100644 --- a/src/PeclEvLoop.php +++ b/src/PeclEvLoop.php @@ -28,9 +28,6 @@ public function __construct() $this->timers = new SplObjectStorage(); } - /** - * {@inheritdoc} - */ public function addReadStream($stream, callable $listener) { $key = (int) $stream; @@ -56,9 +53,6 @@ private function getStreamListenerClosure($stream, callable $listener) { }; } - /** - * {@inheritdoc} - */ public function addWriteStream($stream, callable $listener) { $key = (int) $stream; @@ -72,9 +66,6 @@ public function addWriteStream($stream, callable $listener) $this->writeStreams[$key] = $event; } - /** - * {@inheritdoc} - */ public function removeReadStream($stream) { $key = (int) $stream; @@ -87,9 +78,6 @@ public function removeReadStream($stream) unset($this->readStreams[$key]); } - /** - * {@inheritdoc} - */ public function removeWriteStream($stream) { $key = (int) $stream; @@ -102,18 +90,12 @@ public function removeWriteStream($stream) unset($this->writeStreams[$key]); } - /** - * {@inheritdoc} - */ public function removeStream($stream) { $this->removeReadStream($stream); $this->removeWriteStream($stream); } - /** - * {@inheritdoc} - */ public function addTimer($interval, callable $callback) { $timer = new Timer($this, $interval, $callback, false); @@ -132,9 +114,6 @@ public function addTimer($interval, callable $callback) return $timer; } - /** - * {@inheritdoc} - */ public function addPeriodicTimer($interval, callable $callback) { $timer = new Timer($this, $interval, $callback, true); @@ -150,9 +129,6 @@ public function addPeriodicTimer($interval, callable $callback) return $timer; } - /** - * {@inheritdoc} - */ public function cancelTimer(TimerInterface $timer) { if (!isset($this->timers[$timer])) { @@ -164,25 +140,16 @@ public function cancelTimer(TimerInterface $timer) $this->timers->detach($timer); } - /** - * {@inheritdoc} - */ public function isTimerActive(TimerInterface $timer) { return $this->timers->contains($timer); } - /** - * {@inheritdoc} - */ public function futureTick(callable $listener) { $this->futureTickQueue->add($listener); } - /** - * {@inheritdoc} - */ public function run() { $this->running = true; @@ -205,9 +172,6 @@ public function run() } } - /** - * {@inheritdoc} - */ public function stop() { $this->running = false; From 41d9d63af619a36324415e5a488c1217b3b237ea Mon Sep 17 00:00:00 2001 From: Ivan Kalita Date: Fri, 21 Apr 2017 12:01:17 +0300 Subject: [PATCH 14/17] Add base test for canceling non-existent timer. --- tests/Timer/AbstractTimerTest.php | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/tests/Timer/AbstractTimerTest.php b/tests/Timer/AbstractTimerTest.php index e930ad37..389f0fb8 100644 --- a/tests/Timer/AbstractTimerTest.php +++ b/tests/Timer/AbstractTimerTest.php @@ -2,10 +2,15 @@ namespace React\Tests\EventLoop\Timer; +use React\EventLoop\LoopInterface; +use React\EventLoop\Timer\Timer; use React\Tests\EventLoop\TestCase; abstract class AbstractTimerTest extends TestCase { + /** + * @return LoopInterface + */ abstract public function createLoop(); public function testAddTimer() @@ -94,4 +99,13 @@ public function testMinimumIntervalOneMicrosecond() $this->assertEquals(0.000001, $timer->getInterval()); } + + public function testCancelNonexistentTimer() + { + $loop = $this->createLoop(); + + $timer = new Timer($loop, 1, function(){}); + + $loop->cancelTimer($timer); + } } From 2ef8ff0ebe8352470e78350f37e12e3a694102e6 Mon Sep 17 00:00:00 2001 From: Ivan Kalita Date: Fri, 21 Apr 2017 11:59:41 +0300 Subject: [PATCH 15/17] Add PeclEvLoop test. --- tests/PeclEvLoopTest.php | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 tests/PeclEvLoopTest.php diff --git a/tests/PeclEvLoopTest.php b/tests/PeclEvLoopTest.php new file mode 100644 index 00000000..c00deb65 --- /dev/null +++ b/tests/PeclEvLoopTest.php @@ -0,0 +1,17 @@ +markTestSkipped('pecl-ev tests skipped because ext-ev is not installed.'); + } + + return new PeclEvLoop(); + } +} \ No newline at end of file From 54710a3a7871d1f2e90882a65ba29729083720f8 Mon Sep 17 00:00:00 2001 From: Ivan Kalita Date: Fri, 21 Apr 2017 12:04:38 +0300 Subject: [PATCH 16/17] Add PeclEvLoopTimerTest. --- tests/Timer/PeclEvLoopTimerTest.php | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 tests/Timer/PeclEvLoopTimerTest.php diff --git a/tests/Timer/PeclEvLoopTimerTest.php b/tests/Timer/PeclEvLoopTimerTest.php new file mode 100644 index 00000000..0a4b3e32 --- /dev/null +++ b/tests/Timer/PeclEvLoopTimerTest.php @@ -0,0 +1,17 @@ +markTestSkipped('pecl-ev tests skipped because ext-ev is not installed.'); + } + + return new PeclEvLoop(); + } +} \ No newline at end of file From 79dd25c44d3675b5a52dd8f24f45ab058c8ef12c Mon Sep 17 00:00:00 2001 From: Ivan Kalita Date: Sat, 8 Apr 2017 19:59:10 +0300 Subject: [PATCH 17/17] Add PECL ev extension to travis-init.sh. --- travis-init.sh | 3 +++ 1 file changed, 3 insertions(+) diff --git a/travis-init.sh b/travis-init.sh index 87456016..955e8847 100755 --- a/travis-init.sh +++ b/travis-init.sh @@ -8,6 +8,9 @@ if [[ "$TRAVIS_PHP_VERSION" != "hhvm" && # install 'event' PHP extension echo "yes" | pecl install event + # install 'ev' PHP extension + echo "yes" | pecl install ev + # install 'libevent' PHP extension (does not support php 7) if [[ "$TRAVIS_PHP_VERSION" != "7.0" && "$TRAVIS_PHP_VERSION" != "7.1" ]]; then pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy