Skip to content

Commit ef22aec

Browse files
authored
Merge pull request #88 from jsor-labs/update-master-from-0.4
Add tests for double watchers to be ignored
2 parents a756442 + 94ef249 commit ef22aec

2 files changed

Lines changed: 32 additions & 0 deletions

File tree

src/LibEvLoop.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,10 @@ public function __construct()
3535
*/
3636
public function addReadStream($stream, callable $listener)
3737
{
38+
if (isset($this->readEvents[(int) $stream])) {
39+
return;
40+
}
41+
3842
$callback = function () use ($stream, $listener) {
3943
call_user_func($listener, $stream, $this);
4044
};
@@ -50,6 +54,10 @@ public function addReadStream($stream, callable $listener)
5054
*/
5155
public function addWriteStream($stream, callable $listener)
5256
{
57+
if (isset($this->writeEvents[(int) $stream])) {
58+
return;
59+
}
60+
5361
$callback = function () use ($stream, $listener) {
5462
call_user_func($listener, $stream, $this);
5563
};

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->tickLoop($this->loop);
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->tickLoop($this->loop);
59+
60+
fwrite($output, "bar\n");
61+
$this->tickLoop($this->loop);
62+
}
63+
5064
public function testAddWriteStream()
5165
{
5266
list ($input) = $this->createSocketPair();
@@ -56,6 +70,16 @@ public function testAddWriteStream()
5670
$this->tickLoop($this->loop);
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->tickLoop($this->loop);
80+
$this->tickLoop($this->loop);
81+
}
82+
5983
public function testRemoveReadStreamInstantly()
6084
{
6185
list ($input, $output) = $this->createSocketPair();

0 commit comments

Comments
 (0)