Skip to content

Commit

Permalink
Merge pull request #118 from clue-labs/remove-removestream
Browse files Browse the repository at this point in the history
[RFC] Remove removeStream() method, use removeReadStream/removeWriteStream instead
  • Loading branch information
WyriHaximus authored Nov 10, 2017
2 parents 55f2d96 + f201956 commit f94c3ea
Show file tree
Hide file tree
Showing 8 changed files with 6 additions and 77 deletions.
10 changes: 1 addition & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ $loop->addReadStream($server, function ($server) use ($loop) {
$written = fwrite($conn, $data);
if ($written === strlen($data)) {
fclose($conn);
$loop->removeStream($conn);
$loop->removeWriteStream($conn);
} else {
$data = substr($data, $written);
}
Expand Down Expand Up @@ -437,14 +437,6 @@ remove the write event listener for the given stream.
Removing a stream from the loop that has already been removed or trying
to remove a stream that was never added or is invalid has no effect.

### removeStream()

The `removeStream(resource $stream): void` method can be used to
remove all listeners for the given stream.

Removing a stream from the loop that has already been removed or trying
to remove a stream that was never added or is invalid has no effect.

## Install

The recommended way to install this library is [through Composer](http://getcomposer.org).
Expand Down
2 changes: 1 addition & 1 deletion examples/21-http-server.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
$written = fwrite($conn, $data);
if ($written === strlen($data)) {
fclose($conn);
$loop->removeStream($conn);
$loop->removeWriteStream($conn);
} else {
$data = substr($data, $written);
}
Expand Down
5 changes: 1 addition & 4 deletions src/ExtEventLoop.php
Original file line number Diff line number Diff line change
Expand Up @@ -111,10 +111,7 @@ public function removeWriteStream($stream)
}
}

/**
* {@inheritdoc}
*/
public function removeStream($stream)
private function removeStream($stream)
{
$key = (int) $stream;

Expand Down
9 changes: 0 additions & 9 deletions src/LibEvLoop.php
Original file line number Diff line number Diff line change
Expand Up @@ -118,15 +118,6 @@ public function removeWriteStream($stream)
}
}

/**
* {@inheritdoc}
*/
public function removeStream($stream)
{
$this->removeReadStream($stream);
$this->removeWriteStream($stream);
}

/**
* {@inheritdoc}
*/
Expand Down
5 changes: 1 addition & 4 deletions src/LibEventLoop.php
Original file line number Diff line number Diff line change
Expand Up @@ -116,10 +116,7 @@ public function removeWriteStream($stream)
}
}

/**
* {@inheritdoc}
*/
public function removeStream($stream)
private function removeStream($stream)
{
$key = (int) $stream;

Expand Down
10 changes: 0 additions & 10 deletions src/LoopInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -120,16 +120,6 @@ public function removeReadStream($stream);
*/
public function removeWriteStream($stream);

/**
* Remove all listeners for the given stream.
*
* Removing a stream from the loop that has already been removed or trying
* to remove a stream that was never added or is invalid has no effect.
*
* @param resource $stream The PHP stream resource.
*/
public function removeStream($stream);

/**
* Enqueue a callback to be invoked once after the given interval.
*
Expand Down
9 changes: 0 additions & 9 deletions src/StreamSelectLoop.php
Original file line number Diff line number Diff line change
Expand Up @@ -102,15 +102,6 @@ public function removeWriteStream($stream)
);
}

/**
* {@inheritdoc}
*/
public function removeStream($stream)
{
$this->removeReadStream($stream);
$this->removeWriteStream($stream);
}

/**
* {@inheritdoc}
*/
Expand Down
33 changes: 2 additions & 31 deletions tests/AbstractLoopTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -126,18 +126,6 @@ public function testRemoveWriteStreamAfterWriting()
$this->tickLoop($this->loop);
}

public function testRemoveStreamInstantly()
{
list ($input, $output) = $this->createSocketPair();

$this->loop->addReadStream($input, $this->expectCallableNever());
$this->loop->addWriteStream($input, $this->expectCallableNever());
$this->loop->removeStream($input);

fwrite($output, "bar\n");
$this->tickLoop($this->loop);
}

public function testRemoveStreamForReadOnly()
{
list ($input, $output) = $this->createSocketPair();
Expand All @@ -163,30 +151,13 @@ public function testRemoveStreamForWriteOnly()
$this->tickLoop($this->loop);
}

public function testRemoveStream()
{
list ($input, $output) = $this->createSocketPair();

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

fwrite($output, "bar\n");
$this->tickLoop($this->loop);

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

fwrite($output, "bar\n");
$this->tickLoop($this->loop);
}

public function testRemoveInvalid()
{
list ($stream) = $this->createSocketPair();

// remove a valid stream from the event loop that was never added in the first place
$this->loop->removeReadStream($stream);
$this->loop->removeWriteStream($stream);
$this->loop->removeStream($stream);
}

/** @test */
Expand All @@ -202,7 +173,7 @@ public function runShouldReturnWhenNoMoreFds()

$loop = $this->loop;
$this->loop->addReadStream($input, function ($stream) use ($loop) {
$loop->removeStream($stream);
$loop->removeReadStream($stream);
});

fwrite($output, "foo\n");
Expand Down Expand Up @@ -366,7 +337,7 @@ public function testRunWaitsForFutureTickEvents()
$this->loop->addWriteStream(
$stream,
function () use ($stream) {
$this->loop->removeStream($stream);
$this->loop->removeWriteStream($stream);
$this->loop->futureTick(
function () {
echo 'future-tick' . PHP_EOL;
Expand Down

0 comments on commit f94c3ea

Please sign in to comment.