Skip to content

Commit f524a09

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

File tree

1 file changed

+4
-9
lines changed

1 file changed

+4
-9
lines changed

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

+4-9
Original file line numberDiff line numberDiff line change
@@ -13,21 +13,16 @@ final class FallbackSubscriptionConsumer implements SubscriptionConsumer
1313
*
1414
* @var array
1515
*/
16-
private $subscribers;
16+
private $subscribers = [];
1717

1818
/**
1919
* @var int
2020
*/
2121
private $idleTime = 0;
2222

23-
public function __construct()
24-
{
25-
$this->subscribers = [];
26-
}
27-
2823
public function consume(int $timeout = 0): void
2924
{
30-
if (empty($this->subscribers)) {
25+
if (!$subscriberCount = \count($this->subscribers)) {
3126
throw new \LogicException('No subscribers');
3227
}
3328

@@ -41,13 +36,13 @@ public function consume(int $timeout = 0): void
4136
* @var callable $processor
4237
*/
4338
foreach ($this->subscribers as $queueName => list($consumer, $callback)) {
44-
$message = $consumer->receiveNoWait();
39+
$message = 1 === $subscriberCount ? $consumer->receive((int) ($timeout * 1000)) : $consumer->receiveNoWait();
4540

4641
if ($message) {
4742
if (false === call_user_func($callback, $message, $consumer)) {
4843
return;
4944
}
50-
} else {
45+
} elseif (1 !== $subscriberCount) {
5146
if ($timeout && microtime(true) >= $endAt) {
5247
return;
5348
}

0 commit comments

Comments
 (0)