Skip to content

Commit 6fc8d30

Browse files
committed
Avoid receiveNoWait when only one subscriber
1 parent 094b446 commit 6fc8d30

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

Diff for: pkg/enqueue/Consumption/FallbackSubscriptionConsumer.php

+5-5
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,13 @@ public function __construct()
2525
$this->subscribers = [];
2626
}
2727

28-
public function consume(int $timeout = 0): void
28+
public function consume(int $timeoutMs = 0): void
2929
{
30-
if (empty($this->subscribers)) {
30+
if (!$subscriberCount = \count($this->subscribers)) {
3131
throw new \LogicException('No subscribers');
3232
}
3333

34-
$timeout /= 1000;
34+
$timeout = $timeoutMs / 1000;
3535
$endAt = microtime(true) + $timeout;
3636

3737
while (true) {
@@ -41,13 +41,13 @@ public function consume(int $timeout = 0): void
4141
* @var callable $processor
4242
*/
4343
foreach ($this->subscribers as $queueName => list($consumer, $callback)) {
44-
$message = $consumer->receiveNoWait();
44+
$message = 1 === $subscriberCount ? $consumer->receive($timeoutMs) : $consumer->receiveNoWait();
4545

4646
if ($message) {
4747
if (false === call_user_func($callback, $message, $consumer)) {
4848
return;
4949
}
50-
} else {
50+
} elseif (1 !== $subscriberCount) {
5151
if ($timeout && microtime(true) >= $endAt) {
5252
return;
5353
}

0 commit comments

Comments
 (0)