private function addNextRequest()
    {
        add_next:

        if ($this->isRealized || !$this->iter || !$this->iter->valid()) {
            return false;
        }

        $request = $this->iter->current();
        $this->iter->next();

        if (!($request instanceof RequestInterface)) {
            throw new \InvalidArgumentException(sprintf(
                'All requests in the provided iterator must implement '
                . 'RequestInterface. Found %s',
                Core::describeType($request)
            ));
        }

        // Be sure to use "lazy" futures, meaning they do not send right away.
        $request->getConfig()->set('future', 'lazy');
        $hash = spl_object_hash($request);
        $this->attachListeners($request, $this->eventListeners);
        $request->getEmitter()->on('before', [$this, '_trackRetries'], RequestEvents::EARLY);
        $response = $this->client->send($request);
        $this->waitQueue[$hash] = $response;
        $promise = $response->promise();

        // Don't recursively call itself for completed or rejected responses.
        if ($promise instanceof FulfilledPromise
            || $promise instanceof RejectedPromise
        ) {
            try {
                $this->finishResponse($request, $response->wait(), $hash);
            } catch (\Exception $e) {
                $this->finishResponse($request, $e, $hash);
            }
            goto add_next;
        }

        // Use this function for both resolution and rejection.
        $thenFn = function ($value) use ($request, $hash) {
            $this->finishResponse($request, $value, $hash);
            if (!$request->getConfig()->get('_pool_retries')) {
                $this->addNextRequests();
            }
        };

        $promise->then($thenFn, $thenFn);

        return true;
    }
private function addNextRequest()
    {
        add_next:

        if ($this->isRealized || !$this->iter || !$this->iter->valid()) {
            return false;
        }

        $request = $this->iter->current();
        $this->iter->next();

        if (!($request instanceof RequestInterface)) {
            throw new \InvalidArgumentException(sprintf(
                'All requests in the provided iterator must implement '
                . 'RequestInterface. Found %s',
                Core::describeType($request)
            ));
        }

        // Be sure to use "lazy" futures, meaning they do not send right away.
        $request->getConfig()->set('future', 'lazy');
        $hash = spl_object_hash($request);
        $this->attachListeners($request, $this->eventListeners);
        $request->getEmitter()->on('before', [$this, '_trackRetries'], RequestEvents::EARLY);
        $response = $this->client->send($request);
        $this->waitQueue[$hash] = $response;
        $promise = $response->promise();

        // Don't recursively call itself for completed or rejected responses.
        if ($promise instanceof FulfilledPromise
            || $promise instanceof RejectedPromise
        ) {
            try {
                $this->finishResponse($request, $response->wait(), $hash);
            } catch (\Exception $e) {
                $this->finishResponse($request, $e, $hash);
            }
            goto add_next;
        }

        // Use this function for both resolution and rejection.
        $thenFn = function ($value) use ($request, $hash) {
            $this->finishResponse($request, $value, $hash);
            if (!$request->getConfig()->get('_pool_retries')) {
                $this->addNextRequests();
            }
        };

        $promise->then($thenFn, $thenFn);

        return true;
    }
private function addNextRequest ( ) { add_next : if ( $ this -> isRealized || ! $ this -> iter || ! $ this -> iter -> valid ( ) ) { return false ; } $ request = $ this -> iter -> current ( ) ; $ this -> iter -> next ( ) ; if ( ! ( $ request instanceof RequestInterface ) ) { throw new \ InvalidArgumentException ( sprintf ( 'All requests in the provided iterator must implement ' . 'RequestInterface. Found %s' , Core :: describeType ( $ request ) ) ) ; } // Be sure to use "lazy" futures, meaning they do not send right away. $ request -> getConfig ( ) -> set ( 'future' , 'lazy' ) ; $ hash = spl_object_hash ( $ request ) ; $ this -> attachListeners ( $ request , $ this -> eventListeners ) ; $ request -> getEmitter ( ) -> on ( 'before' , [ $ this , '_trackRetries' ] , RequestEvents :: EARLY ) ; $ response = $ this -> client -> send ( $ request ) ; $ this -> waitQueue [ $ hash ] = $ response ; $ promise = $ response -> promise ( ) ; // Don't recursively call itself for completed or rejected responses. if ( $ promise instanceof FulfilledPromise || $ promise instanceof RejectedPromise ) { try { $ this -> finishResponse ( $ request , $ response -> wait ( ) , $ hash ) ; } catch ( \ Exception $ e ) { $ this -> finishResponse ( $ request , $ e , $ hash ) ; } goto add_next ; } // Use this function for both resolution and rejection. $ thenFn = function ( $ value ) use ( $ request , $ hash ) { $ this -> finishResponse ( $ request , $ value , $ hash ) ; if ( ! $ request -> getConfig ( ) -> get ( '_pool_retries' ) ) { $ this -> addNextRequests ( ) ; } } ; $ promise -> then ( $ thenFn , $ thenFn ) ; return true ; }
Adds the next request to pool and tracks what requests need to be
dereferenced when completing the pool.
Adds the next request to pool and tracks what requests need to be dereferenced when completing the pool .