Skip to content

Commit 18a0564

Browse files
committed
Pass TTL to idle generator and handle false TTL
1 parent 2fe8924 commit 18a0564

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

src/Idle.php

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ public function await(callable $callback): void
5454
protected function listen(callable $callback, CarbonInterface $ttl): void
5555
{
5656
// Iterate over responses yielded by the idle generator.
57-
foreach ($this->idle() as $response) {
57+
foreach ($this->idle($ttl) as $response) {
5858
if (! $response instanceof UntaggedResponse) {
5959
continue;
6060
}
@@ -67,6 +67,10 @@ protected function listen(callable $callback, CarbonInterface $ttl): void
6767
$ttl = $this->getNextTimeout();
6868
}
6969

70+
if ($ttl === false) {
71+
break;
72+
}
73+
7074
// If we've been idle too long, break out to restart the session.
7175
if (Carbon::now()->greaterThanOrEqualTo($ttl)) {
7276
$this->restart();
@@ -143,9 +147,11 @@ protected function done(): void
143147
/**
144148
* Begin a new IDLE session as a generator.
145149
*/
146-
protected function idle(): Generator
150+
protected function idle(CarbonInterface $ttl): Generator
147151
{
148-
yield from $this->mailbox->connection()->idle($this->timeout);
152+
yield from $this->mailbox->connection()->idle(
153+
(int) Carbon::now()->diffInSeconds($ttl)
154+
);
149155
}
150156

151157
/**

0 commit comments

Comments
 (0)