private function pull(): Worker
    {
        if (!$this->isRunning()) {
            throw new StatusError("The pool was shutdown");
        }

        do {
            if ($this->idleWorkers->isEmpty()) {
                if ($this->getWorkerCount() >= $this->maxSize) {
                    // All possible workers busy, so shift from head (will be pushed back onto tail below).
                    $worker = $this->busyQueue->shift();
                } else {
                    // Max worker count has not been reached, so create another worker.
                    $worker = $this->factory->create();
                    $this->workers->attach($worker, 0);
                    break;
                }
            } else {
                // Shift a worker off the idle queue.
                $worker = $this->idleWorkers->shift();
            }

            if ($worker->isRunning()) {
                break;
            }

            $this->workers->detach($worker);
        } while (true);

        $this->busyQueue->push($worker);
        $this->workers[$worker] += 1;

        return $worker;
    }
private function pull(): Worker
    {
        if (!$this->isRunning()) {
            throw new StatusError("The pool was shutdown");
        }

        do {
            if ($this->idleWorkers->isEmpty()) {
                if ($this->getWorkerCount() >= $this->maxSize) {
                    // All possible workers busy, so shift from head (will be pushed back onto tail below).
                    $worker = $this->busyQueue->shift();
                } else {
                    // Max worker count has not been reached, so create another worker.
                    $worker = $this->factory->create();
                    $this->workers->attach($worker, 0);
                    break;
                }
            } else {
                // Shift a worker off the idle queue.
                $worker = $this->idleWorkers->shift();
            }

            if ($worker->isRunning()) {
                break;
            }

            $this->workers->detach($worker);
        } while (true);

        $this->busyQueue->push($worker);
        $this->workers[$worker] += 1;

        return $worker;
    }
private function pull ( ) : Worker { if ( ! $ this -> isRunning ( ) ) { throw new StatusError ( "The pool was shutdown" ) ; } do { if ( $ this -> idleWorkers -> isEmpty ( ) ) { if ( $ this -> getWorkerCount ( ) >= $ this -> maxSize ) { // All possible workers busy, so shift from head (will be pushed back onto tail below). $ worker = $ this -> busyQueue -> shift ( ) ; } else { // Max worker count has not been reached, so create another worker. $ worker = $ this -> factory -> create ( ) ; $ this -> workers -> attach ( $ worker , 0 ) ; break ; } } else { // Shift a worker off the idle queue. $ worker = $ this -> idleWorkers -> shift ( ) ; } if ( $ worker -> isRunning ( ) ) { break ; } $ this -> workers -> detach ( $ worker ) ; } while ( true ) ; $ this -> busyQueue -> push ( $ worker ) ; $ this -> workers [ $ worker ] += 1 ; return $ worker ; }
Pulls a worker from the pool.

@return \Amp\Parallel\Worker\Worker
@throws \Amp\Parallel\Context\StatusError
Pulls a worker from the pool .