Skip to content

Commit 37481ec

Browse files
committed
Merge branch 'refs/heads/future-tick'
2 parents 96257c5 + 191a668 commit 37481ec

File tree

5 files changed

+41
-5
lines changed

5 files changed

+41
-5
lines changed

examples/child-child.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
<?php
22

3-
require __DIR__ . '/../vendor/autoload.php';
4-
53
$i = 0;
64

75
// block all the things!

src/React/EventLoop/ExtEventLoop.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ public function run()
194194
$this->futureTickQueue->tick();
195195

196196
$flags = EventBase::LOOP_ONCE;
197-
if (!$this->running || !$this->futureTickQueue->isEmpty()) {
197+
if (!$this->running || !$this->nextTickQueue->isEmpty() || !$this->futureTickQueue->isEmpty()) {
198198
$flags |= EventBase::LOOP_NONBLOCK;
199199
} elseif (!$this->streamEvents && !$this->timerEvents->count()) {
200200
break;

src/React/EventLoop/LibEvLoop.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ public function run()
198198
$this->futureTickQueue->tick();
199199

200200
$flags = EventLoop::RUN_ONCE;
201-
if (!$this->running || !$this->futureTickQueue->isEmpty()) {
201+
if (!$this->running || !$this->nextTickQueue->isEmpty() || !$this->futureTickQueue->isEmpty()) {
202202
$flags |= EventLoop::RUN_NOWAIT;
203203
} elseif (!$this->readEvents && !$this->writeEvents && !$this->timerEvents->count()) {
204204
break;

src/React/EventLoop/LibEventLoop.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,7 @@ public function run()
202202
$this->futureTickQueue->tick();
203203

204204
$flags = EVLOOP_ONCE;
205-
if (!$this->running || !$this->futureTickQueue->isEmpty()) {
205+
if (!$this->running || !$this->nextTickQueue->isEmpty() || !$this->futureTickQueue->isEmpty()) {
206206
$flags |= EVLOOP_NONBLOCK;
207207
} elseif (!$this->streamEvents && !$this->timerEvents->count()) {
208208
break;

tests/React/Tests/EventLoop/AbstractLoopTest.php

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -320,6 +320,25 @@ function () {
320320
$this->loop->run();
321321
}
322322

323+
public function testNextTickEventGeneratedByFutureTick()
324+
{
325+
$stream = $this->createStream();
326+
327+
$this->loop->futureTick(
328+
function () {
329+
$this->loop->nextTick(
330+
function () {
331+
echo 'next-tick' . PHP_EOL;
332+
}
333+
);
334+
}
335+
);
336+
337+
$this->expectOutputString('next-tick' . PHP_EOL);
338+
339+
$this->loop->run();
340+
}
341+
323342
public function testNextTickEventGeneratedByTimer()
324343
{
325344
$this->loop->addTimer(
@@ -427,6 +446,25 @@ function () {
427446
$this->loop->run();
428447
}
429448

449+
public function testFutureTickEventGeneratedByNextTick()
450+
{
451+
$stream = $this->createStream();
452+
453+
$this->loop->nextTick(
454+
function () {
455+
$this->loop->futureTick(
456+
function () {
457+
echo 'future-tick' . PHP_EOL;
458+
}
459+
);
460+
}
461+
);
462+
463+
$this->expectOutputString('future-tick' . PHP_EOL);
464+
465+
$this->loop->run();
466+
}
467+
430468
public function testFutureTickEventGeneratedByTimer()
431469
{
432470
$this->loop->addTimer(

0 commit comments

Comments
 (0)