Skip to content

Drop tick() from LoopInterface #72

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Feb 3, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

## 0.5.0 (xxxx-xx-xx)

* BC break: Remove `LoopInterface::tick()` (@jsor, #72)

## 0.4.2 (2016-03-07)

* Bug fix: No longer error when signals sent to StreamSelectLoop
Expand Down
13 changes: 0 additions & 13 deletions src/ExtEventLoop.php
Original file line number Diff line number Diff line change
Expand Up @@ -169,19 +169,6 @@ public function futureTick(callable $listener)
$this->futureTickQueue->add($listener);
}

/**
* {@inheritdoc}
*/
public function tick()
{
$this->nextTickQueue->tick();

$this->futureTickQueue->tick();

// @-suppression: https://github.com/reactphp/react/pull/234#discussion-diff-7759616R226
@$this->eventBase->loop(EventBase::LOOP_ONCE | EventBase::LOOP_NONBLOCK);
}

/**
* {@inheritdoc}
*/
Expand Down
12 changes: 0 additions & 12 deletions src/LibEvLoop.php
Original file line number Diff line number Diff line change
Expand Up @@ -173,18 +173,6 @@ public function futureTick(callable $listener)
$this->futureTickQueue->add($listener);
}

/**
* {@inheritdoc}
*/
public function tick()
{
$this->nextTickQueue->tick();

$this->futureTickQueue->tick();

$this->loop->run(EventLoop::RUN_ONCE | EventLoop::RUN_NOWAIT);
}

/**
* {@inheritdoc}
*/
Expand Down
12 changes: 0 additions & 12 deletions src/LibEventLoop.php
Original file line number Diff line number Diff line change
Expand Up @@ -177,18 +177,6 @@ public function futureTick(callable $listener)
$this->futureTickQueue->add($listener);
}

/**
* {@inheritdoc}
*/
public function tick()
{
$this->nextTickQueue->tick();

$this->futureTickQueue->tick();

event_base_loop($this->eventBase, EVLOOP_ONCE | EVLOOP_NONBLOCK);
}

/**
* {@inheritdoc}
*/
Expand Down
5 changes: 0 additions & 5 deletions src/LoopInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -104,11 +104,6 @@ public function nextTick(callable $listener);
*/
public function futureTick(callable $listener);

/**
* Perform a single iteration of the event loop.
*/
public function tick();

/**
* Run the event loop until there are no more tasks to perform.
*/
Expand Down
14 changes: 0 additions & 14 deletions src/StreamSelectLoop.php
Original file line number Diff line number Diff line change
Expand Up @@ -148,20 +148,6 @@ public function futureTick(callable $listener)
$this->futureTickQueue->add($listener);
}

/**
* {@inheritdoc}
*/
public function tick()
{
$this->nextTickQueue->tick();

$this->futureTickQueue->tick();

$this->timers->tick();

$this->waitForStreamActivity(0);
}

/**
* {@inheritdoc}
*/
Expand Down
40 changes: 20 additions & 20 deletions tests/AbstractLoopTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,19 +38,19 @@ public function testAddReadStream()
$this->loop->addReadStream($input, $this->expectCallableExactly(2));

$this->writeToStream($input, "foo\n");
$this->loop->tick();
$this->tickLoop($this->loop);

$this->writeToStream($input, "bar\n");
$this->loop->tick();
$this->tickLoop($this->loop);
}

public function testAddWriteStream()
{
$input = $this->createStream();

$this->loop->addWriteStream($input, $this->expectCallableExactly(2));
$this->loop->tick();
$this->loop->tick();
$this->tickLoop($this->loop);
$this->tickLoop($this->loop);
}

public function testRemoveReadStreamInstantly()
Expand All @@ -61,7 +61,7 @@ public function testRemoveReadStreamInstantly()
$this->loop->removeReadStream($input);

$this->writeToStream($input, "bar\n");
$this->loop->tick();
$this->tickLoop($this->loop);
}

public function testRemoveReadStreamAfterReading()
Expand All @@ -71,12 +71,12 @@ public function testRemoveReadStreamAfterReading()
$this->loop->addReadStream($input, $this->expectCallableOnce());

$this->writeToStream($input, "foo\n");
$this->loop->tick();
$this->tickLoop($this->loop);

$this->loop->removeReadStream($input);

$this->writeToStream($input, "bar\n");
$this->loop->tick();
$this->tickLoop($this->loop);
}

public function testRemoveWriteStreamInstantly()
Expand All @@ -85,18 +85,18 @@ public function testRemoveWriteStreamInstantly()

$this->loop->addWriteStream($input, $this->expectCallableNever());
$this->loop->removeWriteStream($input);
$this->loop->tick();
$this->tickLoop($this->loop);
}

public function testRemoveWriteStreamAfterWriting()
{
$input = $this->createStream();

$this->loop->addWriteStream($input, $this->expectCallableOnce());
$this->loop->tick();
$this->tickLoop($this->loop);

$this->loop->removeWriteStream($input);
$this->loop->tick();
$this->tickLoop($this->loop);
}

public function testRemoveStreamInstantly()
Expand All @@ -108,7 +108,7 @@ public function testRemoveStreamInstantly()
$this->loop->removeStream($input);

$this->writeToStream($input, "bar\n");
$this->loop->tick();
$this->tickLoop($this->loop);
}

public function testRemoveStreamForReadOnly()
Expand All @@ -120,7 +120,7 @@ public function testRemoveStreamForReadOnly()
$this->loop->removeReadStream($input);

$this->writeToStream($input, "foo\n");
$this->loop->tick();
$this->tickLoop($this->loop);
}

public function testRemoveStreamForWriteOnly()
Expand All @@ -133,7 +133,7 @@ public function testRemoveStreamForWriteOnly()
$this->loop->addWriteStream($input, $this->expectCallableNever());
$this->loop->removeWriteStream($input);

$this->loop->tick();
$this->tickLoop($this->loop);
}

public function testRemoveStream()
Expand All @@ -144,12 +144,12 @@ public function testRemoveStream()
$this->loop->addWriteStream($input, $this->expectCallableOnce());

$this->writeToStream($input, "bar\n");
$this->loop->tick();
$this->tickLoop($this->loop);

$this->loop->removeStream($input);

$this->writeToStream($input, "bar\n");
$this->loop->tick();
$this->tickLoop($this->loop);
}

public function testRemoveInvalid()
Expand Down Expand Up @@ -251,7 +251,7 @@ public function testNextTick()

$this->assertFalse($called);

$this->loop->tick();
$this->tickLoop($this->loop);

$this->assertTrue($called);
}
Expand All @@ -275,7 +275,7 @@ function () {

$this->expectOutputString('next-tick' . PHP_EOL . 'stream' . PHP_EOL);

$this->loop->tick();
$this->tickLoop($this->loop);
}

public function testRecursiveNextTick()
Expand All @@ -301,7 +301,7 @@ function () {

$this->expectOutputString('next-tick' . PHP_EOL . 'stream' . PHP_EOL);

$this->loop->tick();
$this->tickLoop($this->loop);
}

public function testRunWaitsForNextTickEvents()
Expand Down Expand Up @@ -375,7 +375,7 @@ public function testFutureTick()

$this->assertFalse($called);

$this->loop->tick();
$this->tickLoop($this->loop);

$this->assertTrue($called);
}
Expand All @@ -399,7 +399,7 @@ function () {

$this->expectOutputString('future-tick' . PHP_EOL . 'stream' . PHP_EOL);

$this->loop->tick();
$this->tickLoop($this->loop);
}

public function testRecursiveFutureTick()
Expand Down
4 changes: 2 additions & 2 deletions tests/ExtEventLoopTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,9 @@ public function testCanUseReadableStreamWithFeatureFds()
$this->loop->addReadStream($input, $this->expectCallableExactly(2));

$this->writeToStream($input, "foo\n");
$this->loop->tick();
$this->tickLoop($this->loop);

$this->writeToStream($input, "bar\n");
$this->loop->tick();
$this->tickLoop($this->loop);
}
}
11 changes: 11 additions & 0 deletions tests/TestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

namespace React\Tests\EventLoop;

use React\EventLoop\LoopInterface;

class TestCase extends \PHPUnit_Framework_TestCase
{
protected function expectCallableExactly($amount)
Expand Down Expand Up @@ -38,4 +40,13 @@ protected function createCallableMock()
{
return $this->getMockBuilder('React\Tests\EventLoop\CallableStub')->getMock();
}

protected function tickLoop(LoopInterface $loop)
{
$loop->futureTick(function () use ($loop) {
$loop->stop();
});

$loop->run();
}
}
20 changes: 10 additions & 10 deletions tests/Timer/AbstractTimerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public function testAddTimer()

$loop->addTimer(0.001, $this->expectCallableOnce());
usleep(1000);
$loop->tick();
$this->tickLoop($loop);
}

public function testAddPeriodicTimer()
Expand All @@ -25,11 +25,11 @@ public function testAddPeriodicTimer()

$loop->addPeriodicTimer(0.001, $this->expectCallableExactly(3));
usleep(1000);
$loop->tick();
$this->tickLoop($loop);
usleep(1000);
$loop->tick();
$this->tickLoop($loop);
usleep(1000);
$loop->tick();
$this->tickLoop($loop);
}

public function testAddPeriodicTimerWithCancel()
Expand All @@ -39,14 +39,14 @@ public function testAddPeriodicTimerWithCancel()
$timer = $loop->addPeriodicTimer(0.001, $this->expectCallableExactly(2));

usleep(1000);
$loop->tick();
$this->tickLoop($loop);
usleep(1000);
$loop->tick();
$this->tickLoop($loop);

$timer->cancel();

usleep(1000);
$loop->tick();
$this->tickLoop($loop);
}

public function testAddPeriodicTimerCancelsItself()
Expand All @@ -64,11 +64,11 @@ public function testAddPeriodicTimerCancelsItself()
});

usleep(1000);
$loop->tick();
$this->tickLoop($loop);
usleep(1000);
$loop->tick();
$this->tickLoop($loop);
usleep(1000);
$loop->tick();
$this->tickLoop($loop);

$this->assertSame(2, $i);
}
Expand Down