Skip to content

Commit

Permalink
Avoid receiveNoWait when only one subscriber
Browse files Browse the repository at this point in the history
  • Loading branch information
deguif committed Nov 8, 2018
1 parent 094b446 commit 8588e82
Showing 1 changed file with 4 additions and 9 deletions.
13 changes: 4 additions & 9 deletions pkg/enqueue/Consumption/FallbackSubscriptionConsumer.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,21 +13,16 @@ final class FallbackSubscriptionConsumer implements SubscriptionConsumer
*
* @var array
*/
private $subscribers;
private $subscribers = [];

/**
* @var int
*/
private $idleTime = 0;

public function __construct()
{
$this->subscribers = [];
}

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

Expand All @@ -41,13 +36,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((int) ($timeout * 1000)) : $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 8588e82

Please sign in to comment.