Skip to content

Commit 0f86217

Browse files
authored
Merge pull request #31 from php-service-bus/master
Merge fix
2 parents 3561e05 + 0df0471 commit 0f86217

File tree

1 file changed

+24
-21
lines changed

1 file changed

+24
-21
lines changed

src/Connection.php

Lines changed: 24 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ final class Connection
5454
private $lastRead = 0;
5555

5656
/**
57-
* @var string
57+
* @var string|null
5858
*/
5959
private $heartbeatWatcherId;
6060

@@ -168,35 +168,38 @@ public function heartbeat(int $interval, ?callable $connectionLost = null): void
168168
{
169169
$this->heartbeatWatcherId = Loop::repeat(
170170
$interval,
171-
function ($watcherId) use ($interval, $connectionLost){
172-
$currentTime = Loop::now();
171+
function (string $watcherId) use ($interval, $connectionLost){
172+
$currentTime = Loop::now();
173173

174-
if (null !== $this->socket) {
175-
$lastWrite = $this->lastWrite ?: $currentTime;
174+
if (null !== $this->socket) {
175+
$lastWrite = $this->lastWrite ?: $currentTime;
176176

177-
$nextHeartbeat = $lastWrite + $interval;
177+
$nextHeartbeat = $lastWrite + $interval;
178178

179-
if ($currentTime >= $nextHeartbeat) {
180-
yield $this->write((new Buffer)
181-
->appendUint8(8)
182-
->appendUint16(0)
183-
->appendUint32(0)
184-
->appendUint8(206)
185-
);
186-
}
179+
if ($currentTime >= $nextHeartbeat) {
180+
yield $this->write((new Buffer)
181+
->appendUint8(8)
182+
->appendUint16(0)
183+
->appendUint32(0)
184+
->appendUint8(206)
185+
);
186+
}
187187

188-
unset($lastWrite, $nextHeartbeat);
189-
}
188+
unset($lastWrite, $nextHeartbeat);
189+
}
190190

191-
if (null !== $connectionLost && 0 !== $this->lastRead) {
192-
if ($currentTime > ($this->lastRead + $interval + 1000)) {
191+
if (
192+
null !== $connectionLost &&
193+
0 !== $this->lastRead &&
194+
$currentTime > ($this->lastRead + $interval + 1000)
195+
)
196+
{
193197
$connectionLost();
194198
Loop::cancel($watcherId);
195199
}
196-
}
197200

198-
unset($currentTime);
199-
});
201+
unset($currentTime);
202+
});
200203
}
201204

202205
public function close(): void

0 commit comments

Comments
 (0)