Skip to content

Commit 1d1773b

Browse files
authored
Merge pull request #86 from kelunik/io-watcher-replacements
Add tests for double watchers to be ignored
2 parents f5a8549 + b2acd81 commit 1d1773b

File tree

2 files changed

+32
-0
lines changed

2 files changed

+32
-0
lines changed

src/LibEvLoop.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,10 @@ public function __construct()
3838
*/
3939
public function addReadStream($stream, callable $listener)
4040
{
41+
if (isset($this->readEvents[(int) $stream])) {
42+
return;
43+
}
44+
4145
$callback = function () use ($stream, $listener) {
4246
call_user_func($listener, $stream, $this);
4347
};
@@ -53,6 +57,10 @@ public function addReadStream($stream, callable $listener)
5357
*/
5458
public function addWriteStream($stream, callable $listener)
5559
{
60+
if (isset($this->writeEvents[(int) $stream])) {
61+
return;
62+
}
63+
5664
$callback = function () use ($stream, $listener) {
5765
call_user_func($listener, $stream, $this);
5866
};

tests/AbstractLoopTest.php

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,20 @@ public function testAddReadStream()
4747
$this->loop->tick();
4848
}
4949

50+
public function testAddReadStreamIgnoresSecondCallable()
51+
{
52+
list ($input, $output) = $this->createSocketPair();
53+
54+
$this->loop->addReadStream($input, $this->expectCallableExactly(2));
55+
$this->loop->addReadStream($input, $this->expectCallableNever());
56+
57+
fwrite($output, "foo\n");
58+
$this->loop->tick();
59+
60+
fwrite($output, "bar\n");
61+
$this->loop->tick();
62+
}
63+
5064
public function testAddWriteStream()
5165
{
5266
list ($input) = $this->createSocketPair();
@@ -56,6 +70,16 @@ public function testAddWriteStream()
5670
$this->loop->tick();
5771
}
5872

73+
public function testAddWriteStreamIgnoresSecondCallable()
74+
{
75+
list ($input) = $this->createSocketPair();
76+
77+
$this->loop->addWriteStream($input, $this->expectCallableExactly(2));
78+
$this->loop->addWriteStream($input, $this->expectCallableNever());
79+
$this->loop->tick();
80+
$this->loop->tick();
81+
}
82+
5983
public function testRemoveReadStreamInstantly()
6084
{
6185
list ($input, $output) = $this->createSocketPair();

0 commit comments

Comments
 (0)