diff --git a/src/ExtEventLoop.php b/src/ExtEventLoop.php index 593c2c62..51704475 100644 --- a/src/ExtEventLoop.php +++ b/src/ExtEventLoop.php @@ -6,7 +6,6 @@ use EventBase; use EventConfig as EventBaseConfig; use React\EventLoop\Tick\FutureTickQueue; -use React\EventLoop\Tick\NextTickQueue; use React\EventLoop\Timer\Timer; use React\EventLoop\Timer\TimerInterface; use SplObjectStorage; @@ -17,7 +16,6 @@ class ExtEventLoop implements LoopInterface { private $eventBase; - private $nextTickQueue; private $futureTickQueue; private $timerCallback; private $timerEvents; @@ -31,7 +29,6 @@ class ExtEventLoop implements LoopInterface public function __construct(EventBaseConfig $config = null) { $this->eventBase = new EventBase($config); - $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} */ @@ -177,12 +166,10 @@ public function run() $this->running = true; while ($this->running) { - $this->nextTickQueue->tick(); - $this->futureTickQueue->tick(); $flags = EventBase::LOOP_ONCE; - if (!$this->running || !$this->nextTickQueue->isEmpty() || !$this->futureTickQueue->isEmpty()) { + if (!$this->running || !$this->futureTickQueue->isEmpty()) { $flags |= EventBase::LOOP_NONBLOCK; } elseif (!$this->streamEvents && !$this->timerEvents->count()) { break; diff --git a/src/LibEvLoop.php b/src/LibEvLoop.php index ca3426a9..1f0124ae 100644 --- a/src/LibEvLoop.php +++ b/src/LibEvLoop.php @@ -6,7 +6,6 @@ use libev\IOEvent; use libev\TimerEvent; use React\EventLoop\Tick\FutureTickQueue; -use React\EventLoop\Tick\NextTickQueue; use React\EventLoop\Timer\Timer; use React\EventLoop\Timer\TimerInterface; use SplObjectStorage; @@ -18,7 +17,6 @@ class LibEvLoop implements LoopInterface { private $loop; - private $nextTickQueue; private $futureTickQueue; private $timerEvents; private $readEvents = []; @@ -28,7 +26,6 @@ class LibEvLoop implements LoopInterface public function __construct() { $this->loop = new EventLoop(); - $this->nextTickQueue = new NextTickQueue($this); $this->futureTickQueue = new FutureTickQueue($this); $this->timerEvents = new SplObjectStorage(); } @@ -157,14 +154,6 @@ public function isTimerActive(TimerInterface $timer) return $this->timerEvents->contains($timer); } - /** - * {@inheritdoc} - */ - public function nextTick(callable $listener) - { - $this->nextTickQueue->add($listener); - } - /** * {@inheritdoc} */ @@ -181,12 +170,10 @@ public function run() $this->running = true; while ($this->running) { - $this->nextTickQueue->tick(); - $this->futureTickQueue->tick(); $flags = EventLoop::RUN_ONCE; - if (!$this->running || !$this->nextTickQueue->isEmpty() || !$this->futureTickQueue->isEmpty()) { + if (!$this->running || !$this->futureTickQueue->isEmpty()) { $flags |= EventLoop::RUN_NOWAIT; } elseif (!$this->readEvents && !$this->writeEvents && !$this->timerEvents->count()) { break; diff --git a/src/LibEventLoop.php b/src/LibEventLoop.php index f6a4aba0..b2c771cf 100644 --- a/src/LibEventLoop.php +++ b/src/LibEventLoop.php @@ -5,7 +5,6 @@ use Event; use EventBase; use React\EventLoop\Tick\FutureTickQueue; -use React\EventLoop\Tick\NextTickQueue; use React\EventLoop\Timer\Timer; use React\EventLoop\Timer\TimerInterface; use SplObjectStorage; @@ -18,7 +17,6 @@ class LibEventLoop implements LoopInterface const MICROSECONDS_PER_SECOND = 1000000; private $eventBase; - private $nextTickQueue; private $futureTickQueue; private $timerCallback; private $timerEvents; @@ -32,7 +30,6 @@ class LibEventLoop implements LoopInterface public function __construct() { $this->eventBase = event_base_new(); - $this->nextTickQueue = new NextTickQueue($this); $this->futureTickQueue = new FutureTickQueue($this); $this->timerEvents = new SplObjectStorage(); @@ -161,14 +158,6 @@ public function isTimerActive(TimerInterface $timer) return $this->timerEvents->contains($timer); } - /** - * {@inheritdoc} - */ - public function nextTick(callable $listener) - { - $this->nextTickQueue->add($listener); - } - /** * {@inheritdoc} */ @@ -185,12 +174,10 @@ public function run() $this->running = true; while ($this->running) { - $this->nextTickQueue->tick(); - $this->futureTickQueue->tick(); $flags = EVLOOP_ONCE; - if (!$this->running || !$this->nextTickQueue->isEmpty() || !$this->futureTickQueue->isEmpty()) { + if (!$this->running || !$this->futureTickQueue->isEmpty()) { $flags |= EVLOOP_NONBLOCK; } elseif (!$this->streamEvents && !$this->timerEvents->count()) { break; diff --git a/src/LoopInterface.php b/src/LoopInterface.php index bb01d720..b4750dd0 100644 --- a/src/LoopInterface.php +++ b/src/LoopInterface.php @@ -85,16 +85,6 @@ public function cancelTimer(TimerInterface $timer); */ public function isTimerActive(TimerInterface $timer); - /** - * Schedule a callback to be invoked on the next tick of the event loop. - * - * Callbacks are guaranteed to be executed in the order they are enqueued, - * before any timer or stream events. - * - * @param callable $listener The callback to invoke. - */ - public function nextTick(callable $listener); - /** * Schedule a callback to be invoked on a future tick of the event loop. * diff --git a/src/StreamSelectLoop.php b/src/StreamSelectLoop.php index f0d68e1a..da5ddaa4 100644 --- a/src/StreamSelectLoop.php +++ b/src/StreamSelectLoop.php @@ -3,7 +3,6 @@ namespace React\EventLoop; use React\EventLoop\Tick\FutureTickQueue; -use React\EventLoop\Tick\NextTickQueue; use React\EventLoop\Timer\Timer; use React\EventLoop\Timer\TimerInterface; use React\EventLoop\Timer\Timers; @@ -15,7 +14,6 @@ class StreamSelectLoop implements LoopInterface { const MICROSECONDS_PER_SECOND = 1000000; - private $nextTickQueue; private $futureTickQueue; private $timers; private $readStreams = []; @@ -26,7 +24,6 @@ class StreamSelectLoop implements LoopInterface public function __construct() { - $this->nextTickQueue = new NextTickQueue($this); $this->futureTickQueue = new FutureTickQueue($this); $this->timers = new Timers(); } @@ -132,14 +129,6 @@ public function isTimerActive(TimerInterface $timer) return $this->timers->contains($timer); } - /** - * {@inheritdoc} - */ - public function nextTick(callable $listener) - { - $this->nextTickQueue->add($listener); - } - /** * {@inheritdoc} */ @@ -156,14 +145,12 @@ public function run() $this->running = true; while ($this->running) { - $this->nextTickQueue->tick(); - $this->futureTickQueue->tick(); $this->timers->tick(); - // Next-tick or future-tick queues have pending callbacks ... - if (!$this->running || !$this->nextTickQueue->isEmpty() || !$this->futureTickQueue->isEmpty()) { + // Future-tick queue has pending callbacks ... + if (!$this->running || !$this->futureTickQueue->isEmpty()) { $timeout = 0; // There is a pending timer, only block until it is due ... diff --git a/src/Tick/NextTickQueue.php b/src/Tick/NextTickQueue.php deleted file mode 100644 index 5b8e1de8..00000000 --- a/src/Tick/NextTickQueue.php +++ /dev/null @@ -1,57 +0,0 @@ -eventLoop = $eventLoop; - $this->queue = new SplQueue(); - } - - /** - * Add a callback to be invoked on the next tick of the event loop. - * - * Callbacks are guaranteed to be executed in the order they are enqueued, - * before any timer or stream events. - * - * @param callable $listener The callback to invoke. - */ - public function add(callable $listener) - { - $this->queue->enqueue($listener); - } - - /** - * Flush the callback queue. - */ - public function tick() - { - while (!$this->queue->isEmpty()) { - call_user_func( - $this->queue->dequeue(), - $this->eventLoop - ); - } - } - - /** - * Check if the next tick queue is empty. - * - * @return boolean - */ - public function isEmpty() - { - return $this->queue->isEmpty(); - } -} diff --git a/tests/AbstractLoopTest.php b/tests/AbstractLoopTest.php index c45c4d7a..8c175a67 100644 --- a/tests/AbstractLoopTest.php +++ b/tests/AbstractLoopTest.php @@ -207,7 +207,7 @@ function () { } ); - $this->loop->nextTick( + $this->loop->futureTick( function () { $this->loop->stop(); } @@ -238,126 +238,19 @@ public function testIgnoreRemovedCallback() $loop->run(); } - public function testNextTick() - { - $called = false; - - $callback = function ($loop) use (&$called) { - $this->assertSame($this->loop, $loop); - $called = true; - }; - - $this->loop->nextTick($callback); - - $this->assertFalse($called); - - $this->tickLoop($this->loop); - - $this->assertTrue($called); - } - - public function testNextTickFiresBeforeIO() + public function testFutureTickEventGeneratedByFutureTick() { - $stream = $this->createStream(); - - $this->loop->addWriteStream( - $stream, - function () { - echo 'stream' . PHP_EOL; - } - ); - - $this->loop->nextTick( - function () { - echo 'next-tick' . PHP_EOL; - } - ); - - $this->expectOutputString('next-tick' . PHP_EOL . 'stream' . PHP_EOL); - - $this->tickLoop($this->loop); - } - - public function testRecursiveNextTick() - { - $stream = $this->createStream(); - - $this->loop->addWriteStream( - $stream, - function () { - echo 'stream' . PHP_EOL; - } - ); - - $this->loop->nextTick( - function () { - $this->loop->nextTick( - function () { - echo 'next-tick' . PHP_EOL; - } - ); - } - ); - - $this->expectOutputString('next-tick' . PHP_EOL . 'stream' . PHP_EOL); - - $this->tickLoop($this->loop); - } - - public function testRunWaitsForNextTickEvents() - { - $stream = $this->createStream(); - - $this->loop->addWriteStream( - $stream, - function () use ($stream) { - $this->loop->removeStream($stream); - $this->loop->nextTick( - function () { - echo 'next-tick' . PHP_EOL; - } - ); - } - ); - - $this->expectOutputString('next-tick' . PHP_EOL); - - $this->loop->run(); - } - - public function testNextTickEventGeneratedByFutureTick() - { - $stream = $this->createStream(); - $this->loop->futureTick( function () { - $this->loop->nextTick( - function () { - echo 'next-tick' . PHP_EOL; - } - ); - } - ); - - $this->expectOutputString('next-tick' . PHP_EOL); - - $this->loop->run(); - } - - public function testNextTickEventGeneratedByTimer() - { - $this->loop->addTimer( - 0.001, - function () { - $this->loop->nextTick( + $this->loop->futureTick( function () { - echo 'next-tick' . PHP_EOL; + echo 'future-tick' . PHP_EOL; } ); } ); - $this->expectOutputString('next-tick' . PHP_EOL); + $this->expectOutputString('future-tick' . PHP_EOL); $this->loop->run(); } @@ -451,25 +344,6 @@ function () { $this->loop->run(); } - public function testFutureTickEventGeneratedByNextTick() - { - $stream = $this->createStream(); - - $this->loop->nextTick( - function () { - $this->loop->futureTick( - function () { - echo 'future-tick' . PHP_EOL; - } - ); - } - ); - - $this->expectOutputString('future-tick' . PHP_EOL); - - $this->loop->run(); - } - public function testFutureTickEventGeneratedByTimer() { $this->loop->addTimer(
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: