Runs until all outstanding requests have been completed.

@param  integer $max The number of simultaneous allowed connections.
@return array        The array of responses.
180685
public function flush($max = 10, $options = [])
    {
        $defaults = [
            'selectTimeout'  => 1.0
        ];

        $options += $defaults;

        do {
            $this->select($options['selectTimeout']);
            $this->process($max);
        } while ($this->_running > 0);

        $results = $this->_results;
        $this->_results = [];
        return $results;
    }
1127248
public function createConnection($maxAttempts = 3)
    {

        if (is_null($this->connection)) {
            $lastExcelption = $this->attemptConnection($maxAttempts);

            if (!is_null($lastExcelption)) {
                $this->console->getSfStyleOutput()->error(
                    [
                        "Looks like your Dedicated server is either offline or has wrong config settings",
                        "Error message: " . $lastExcelption->getMessage()
                    ]
                );
                $this->logger->error("Unable to open connection for Dedicated server", ["exception" => $lastExcelption]);

                throw $lastExcelption;
            }

            // Dispatch connected event.
            $event = new GenericEvent($this->connection);
            $this->eventDispatcher->dispatch(self::EVENT_CONNECTED, $event);
        }

        return $this->connection;
    }
996889
public function mostRecentOrdersAction($max = 20)
    {
        $em = $this->getDoctrine()->getManager();

        /** @var ProductOrderRepository $productOrderRepo */
        $productOrderRepo = $em->getRepository('AmulenShopBundle:ProductOrder');
        $orders = $productOrderRepo->recentOrders($max);

        return [
            'orders' => $orders,
        ];
    }
482217
public function listMostPopularAction($max = 3)
    {
        $queries = $this->getSearchRepository()->retrieveMostPopular($max);

        return $this->render(
            'GenjFaqBundle:Search:list_most_popular.html.twig',
            array(
                'queries' => $queries,
                'max'     => $max
            )
        );
    }
188590
public function limit() {
        $args = func_get_args();
        $this->build()->bindExpression('limit', $args[0] . " " . (empty($args[1]) ? '' : ",{$args[1]}"));

        return $this->connection;
    }
1264928
public function iterate(iterable $iterable, ?int $max = null): iterable
    {
        $this->start($max ?? (\is_countable($iterable) ? \count($iterable) : 0));

        foreach ($iterable as $key => $value) {
            yield $key => $value;

            $this->advance();
        }

        $this->finish();
    }
1217159
public function bindSockets($addrs = [], $max = 0)
    {
        if (is_string($addrs)) {
            $addrs = array_map('trim', explode(',', $addrs));
        }
        $n = 0;
        foreach ($addrs as $addr) {
            if ($this->bindSocket($addr)) {
                ++$n;
            }
            if ($max > 0 && ($n >= $max)) {
                return $n;
            }
        }
        return $n;
    }
579860
protected function attemptConnection($maxAttempts)
    {
        $attempts = 0;
        $lastExcelption = null;

        do {

            if (!is_null($lastExcelption)) {
                // Not first error.
                $lastExcelption = null;

                $this->console->getSfStyleOutput()->block(
                    "Will attempt to re-connect to dedicated server in 30seconds"
                );
                sleep(30);
            }

            try {
                $this->console->writeln('Attempting to connect to the dedicated server!');

                $this->connection = Connection::factory(
                    $this->host,
                    $this->port,
                    $this->timeout,
                    $this->user,
                    $this->password
                );

            } catch (\Exception $e) {
                $lastExcelption = $e;
                $attempts++;
                $remainingAttemps = $maxAttempts - $attempts;

                $this->console->getSfStyleOutput()->error(
                    [
                        "Cound't connect to the dedicated server !",
                        "Attempt : $attempts, Remaining attemps : $remainingAttemps ",
                        $e->getMessage(),
                    ]
                );
            }
        } while($attempts < $maxAttempts && !is_null($lastExcelption));

        return $lastExcelption;
    }
73357
private function checkRequestCount($array, $action, $maxReq = self::MAX_DHL_REQUESTS) {
		$count = count($array);

		if($count > self::MAX_DHL_REQUESTS)
			$this->addError('There are only ' . $maxReq . ' Request/s for one call allowed for the action "'
				. $action . '"! You tried to request ' . $count . ' ones');
	}
111800
public function Loop($minSize = 1, $maxSize = null)
    {
        list($min, $max) = $this->resolveMinMax($minSize, $maxSize, 10);
        $limit = rand($min, $max);
        $list = ArrayList::create(array());
        $i = 0;
        while ($i < $limit) {
            $list->push(new DataObject());
            $i++;
        }

        return $list;
    }
878036
protected function executeNextWaitingRequest()
    {
        if (($this->numberOfParallelRequests === 0 || count($this->runningRequests) < $this->numberOfParallelRequests)
            && count($this->waitingRequests) > 0
        ) {
            $this->executeRequest(reset($this->waitingRequests));
        }
        return $this;
    }
623950
public function run($maxSeconds = null)
    {
        if ($maxSeconds !== null) {
            $this->stopTimer = $this->eventLoop->addTimer($maxSeconds, function () {
                $this->stop();
            });
        }

        $this->eventLoop->run();
    }
614479
public function max($max) {
        $this->check_role = 'max';
        $this->p1 = $max;
        $result = $this->value <= $max;
        $this->checkResult($result);
        return $this;
    }
60092
public function setMaxQueryTime($max)
    {
        assert(is_int($max));
        assert($max >= 0);
        $this->_maxquerytime = $max;

        return $this;
    }
1339890
public function setMaxRedirects($maxRedirects)
    {
        $this->maxRedirects = $maxRedirects < 0 ? -1 : $maxRedirects;
        $this->followRedirects = -1 != $this->maxRedirects;
    }
1341303
public function limitSize($max) {
		// if the maximum is not numeric
		if(is_numeric($max)) {
			// set maximum
			$this->Limits->Size = intval($max);
		}
		// return self
		return($this);
	}
170540
protected function calculateRemainingAttempts($key, $maxAttempts, $retryAfter = null)
    {
        if (is_null($retryAfter)) {
            return $this->limiter->retriesLeft($key, $maxAttempts);
        }

        return 0;
    }