Skip to content

[RFC] Remove removeStream() method, use removeReadStream/removeWriteStream instead #118

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 1 commit into from
Nov 10, 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
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 @@ -394,14 +394,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 @@ -88,10 +88,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 @@ -94,15 +94,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 @@ -89,10 +89,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 @@ -80,15 +80,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