Skip to content

Commit f94c3ea

Browse files
authored
Merge pull request #118 from clue-labs/remove-removestream
[RFC] Remove removeStream() method, use removeReadStream/removeWriteStream instead
2 parents 55f2d96 + f201956 commit f94c3ea

8 files changed

Lines changed: 6 additions & 77 deletions

File tree

README.md

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ $loop->addReadStream($server, function ($server) use ($loop) {
4141
$written = fwrite($conn, $data);
4242
if ($written === strlen($data)) {
4343
fclose($conn);
44-
$loop->removeStream($conn);
44+
$loop->removeWriteStream($conn);
4545
} else {
4646
$data = substr($data, $written);
4747
}
@@ -437,14 +437,6 @@ remove the write event listener for the given stream.
437437
Removing a stream from the loop that has already been removed or trying
438438
to remove a stream that was never added or is invalid has no effect.
439439

440-
### removeStream()
441-
442-
The `removeStream(resource $stream): void` method can be used to
443-
remove all listeners for the given stream.
444-
445-
Removing a stream from the loop that has already been removed or trying
446-
to remove a stream that was never added or is invalid has no effect.
447-
448440
## Install
449441

450442
The recommended way to install this library is [through Composer](http://getcomposer.org).

examples/21-http-server.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
$written = fwrite($conn, $data);
1515
if ($written === strlen($data)) {
1616
fclose($conn);
17-
$loop->removeStream($conn);
17+
$loop->removeWriteStream($conn);
1818
} else {
1919
$data = substr($data, $written);
2020
}

src/ExtEventLoop.php

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -111,10 +111,7 @@ public function removeWriteStream($stream)
111111
}
112112
}
113113

114-
/**
115-
* {@inheritdoc}
116-
*/
117-
public function removeStream($stream)
114+
private function removeStream($stream)
118115
{
119116
$key = (int) $stream;
120117

src/LibEvLoop.php

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -118,15 +118,6 @@ public function removeWriteStream($stream)
118118
}
119119
}
120120

121-
/**
122-
* {@inheritdoc}
123-
*/
124-
public function removeStream($stream)
125-
{
126-
$this->removeReadStream($stream);
127-
$this->removeWriteStream($stream);
128-
}
129-
130121
/**
131122
* {@inheritdoc}
132123
*/

src/LibEventLoop.php

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -116,10 +116,7 @@ public function removeWriteStream($stream)
116116
}
117117
}
118118

119-
/**
120-
* {@inheritdoc}
121-
*/
122-
public function removeStream($stream)
119+
private function removeStream($stream)
123120
{
124121
$key = (int) $stream;
125122

src/LoopInterface.php

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -120,16 +120,6 @@ public function removeReadStream($stream);
120120
*/
121121
public function removeWriteStream($stream);
122122

123-
/**
124-
* Remove all listeners for the given stream.
125-
*
126-
* Removing a stream from the loop that has already been removed or trying
127-
* to remove a stream that was never added or is invalid has no effect.
128-
*
129-
* @param resource $stream The PHP stream resource.
130-
*/
131-
public function removeStream($stream);
132-
133123
/**
134124
* Enqueue a callback to be invoked once after the given interval.
135125
*

src/StreamSelectLoop.php

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -102,15 +102,6 @@ public function removeWriteStream($stream)
102102
);
103103
}
104104

105-
/**
106-
* {@inheritdoc}
107-
*/
108-
public function removeStream($stream)
109-
{
110-
$this->removeReadStream($stream);
111-
$this->removeWriteStream($stream);
112-
}
113-
114105
/**
115106
* {@inheritdoc}
116107
*/

tests/AbstractLoopTest.php

Lines changed: 2 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -126,18 +126,6 @@ public function testRemoveWriteStreamAfterWriting()
126126
$this->tickLoop($this->loop);
127127
}
128128

129-
public function testRemoveStreamInstantly()
130-
{
131-
list ($input, $output) = $this->createSocketPair();
132-
133-
$this->loop->addReadStream($input, $this->expectCallableNever());
134-
$this->loop->addWriteStream($input, $this->expectCallableNever());
135-
$this->loop->removeStream($input);
136-
137-
fwrite($output, "bar\n");
138-
$this->tickLoop($this->loop);
139-
}
140-
141129
public function testRemoveStreamForReadOnly()
142130
{
143131
list ($input, $output) = $this->createSocketPair();
@@ -163,30 +151,13 @@ public function testRemoveStreamForWriteOnly()
163151
$this->tickLoop($this->loop);
164152
}
165153

166-
public function testRemoveStream()
167-
{
168-
list ($input, $output) = $this->createSocketPair();
169-
170-
$this->loop->addReadStream($input, $this->expectCallableOnce());
171-
$this->loop->addWriteStream($input, $this->expectCallableOnce());
172-
173-
fwrite($output, "bar\n");
174-
$this->tickLoop($this->loop);
175-
176-
$this->loop->removeStream($input);
177-
178-
fwrite($output, "bar\n");
179-
$this->tickLoop($this->loop);
180-
}
181-
182154
public function testRemoveInvalid()
183155
{
184156
list ($stream) = $this->createSocketPair();
185157

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

192163
/** @test */
@@ -202,7 +173,7 @@ public function runShouldReturnWhenNoMoreFds()
202173

203174
$loop = $this->loop;
204175
$this->loop->addReadStream($input, function ($stream) use ($loop) {
205-
$loop->removeStream($stream);
176+
$loop->removeReadStream($stream);
206177
});
207178

208179
fwrite($output, "foo\n");
@@ -366,7 +337,7 @@ public function testRunWaitsForFutureTickEvents()
366337
$this->loop->addWriteStream(
367338
$stream,
368339
function () use ($stream) {
369-
$this->loop->removeStream($stream);
340+
$this->loop->removeWriteStream($stream);
370341
$this->loop->futureTick(
371342
function () {
372343
echo 'future-tick' . PHP_EOL;

0 commit comments

Comments
 (0)