Skip to content

Commit 78aa1f9

Browse files
committed
Added connection monitoring
1 parent 7020209 commit 78aa1f9

File tree

4 files changed

+23
-6
lines changed

4 files changed

+23
-6
lines changed

composer.json

+7-4
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,13 @@
2020
"require": {
2121
"php": ">=8.0",
2222
"amphp/amp": "v2.6.*",
23-
"amphp/socket": "v1.1.*",
23+
"amphp/socket": "v1.2.*",
2424
"phpinnacle/buffer": "v1.2.*"
2525
},
2626
"require-dev": {
2727
"phpunit/phpunit": "v9.5.*",
28-
"vimeo/psalm": "v4.13.*",
29-
"phpstan/phpstan": "v1.2.*"
28+
"vimeo/psalm": "v4.18.*",
29+
"phpstan/phpstan": "v1.4.*"
3030
},
3131
"prefer-stable": true,
3232
"autoload": {
@@ -52,6 +52,9 @@
5252
},
5353
"config": {
5454
"sort-packages": true,
55-
"optimize-autoloader": true
55+
"optimize-autoloader": true,
56+
"allow-plugins": {
57+
"composer/package-versions-deprecated": false
58+
}
5659
}
5760
}

phpstan.neon

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
parameters:
22
checkMissingIterableValueType: false
33
checkGenericClassInNonGenericObjectType: false
4-
ignoreErrors:
5-
- '#Cannot cast mixed to int#'
4+

src/Client.php

+13
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,8 @@ function () {
136136

137137
$this->connection->write($buffer);
138138
$this->connection->close();
139+
140+
$this->disableConnectionMonitor();
139141
}
140142
);
141143

@@ -161,6 +163,8 @@ function(): void
161163
*/
162164
public function disconnect(int $code = 0, string $reason = ''): Promise
163165
{
166+
$this->disableConnectionMonitor();
167+
164168
return call(
165169
function () use ($code, $reason) {
166170
if (\in_array($this->state, [self::STATE_NOT_CONNECTED, self::STATE_DISCONNECTING])) {
@@ -446,4 +450,13 @@ static function (Protocol\AbstractFrame $frame) use ($deferred) {
446450

447451
return $deferred->promise();
448452
}
453+
454+
private function disableConnectionMonitor(): void {
455+
if($this->connectionMonitorWatcherId !== null) {
456+
457+
Loop::cancel($this->connectionMonitorWatcherId);
458+
459+
$this->connectionMonitorWatcherId = null;
460+
}
461+
}
449462
}

tests/AsyncTest.php

+2
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,8 @@ protected function runTestAsync(...$args)
5353

5454
$return = yield call([$this, $this->realTestName], ...$args);
5555

56+
yield $client->disconnect();
57+
5658
$info = Loop::getInfo();
5759
$count = $info['enabled_watchers']['referenced'];
5860

0 commit comments

Comments
 (0)