Skip to content

Avoid receiveNoWait when only one subscriber #626

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 8, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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