Skip to content

Commit

Permalink
Merge pull request #626 from deguif/master
Browse files Browse the repository at this point in the history
Avoid receiveNoWait when only one subscriber
  • Loading branch information
makasim authored Nov 8, 2018
2 parents 094b446 + 6fc8d30 commit 572310f
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions pkg/enqueue/Consumption/FallbackSubscriptionConsumer.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,13 @@ public function __construct()
$this->subscribers = [];
}

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

$timeout /= 1000;
$timeout = $timeoutMs / 1000;
$endAt = microtime(true) + $timeout;

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

if ($message) {
if (false === call_user_func($callback, $message, $consumer)) {
return;
}
} else {
} elseif (1 !== $subscriberCount) {
if ($timeout && microtime(true) >= $endAt) {
return;
}
Expand Down

0 comments on commit 572310f

Please sign in to comment.