public function add($item, array $tags = [])
    {
        if ($item instanceof RunInterface
            && !($this->isRunning()
                 || $this->runInstantly)
            && $item->isRunning()) {
            throw new NotRunningException("add: unable to add a running item when the pool has not started");
        }

        // special handling of child collections, a pool should only care about leaf nodes
        if ($item instanceof PoolInterface) {
            $item->addListener(
                PoolRunEvent::POOL_RUN_ADDED,
                function (PoolRunEvent $event) {
                    $this->add($event->getRun());
                }
            );
            foreach ($item->getAll() as $child) {
                $this->add($child);
            }
            return $this;
        }

        parent::add($item, $tags);

        if ($item instanceof RunInterface && !$item->hasStarted()) {
            $this->waitingQueue->insert($item, $item->getPriority());
            if ($this->runInstantly) {
                $this->startNext();
            }
        }

        if ($item instanceof PrioritisedInterface && $item instanceof DispatcherInterface) {
            $item->addListener(PriorityChangedEvent::CHANGED, [$this, 'onPriorityChanged']);
        }

        return $this;
    }
public function add($item, array $tags = [])
    {
        if ($item instanceof RunInterface
            && !($this->isRunning()
                 || $this->runInstantly)
            && $item->isRunning()) {
            throw new NotRunningException("add: unable to add a running item when the pool has not started");
        }

        // special handling of child collections, a pool should only care about leaf nodes
        if ($item instanceof PoolInterface) {
            $item->addListener(
                PoolRunEvent::POOL_RUN_ADDED,
                function (PoolRunEvent $event) {
                    $this->add($event->getRun());
                }
            );
            foreach ($item->getAll() as $child) {
                $this->add($child);
            }
            return $this;
        }

        parent::add($item, $tags);

        if ($item instanceof RunInterface && !$item->hasStarted()) {
            $this->waitingQueue->insert($item, $item->getPriority());
            if ($this->runInstantly) {
                $this->startNext();
            }
        }

        if ($item instanceof PrioritisedInterface && $item instanceof DispatcherInterface) {
            $item->addListener(PriorityChangedEvent::CHANGED, [$this, 'onPriorityChanged']);
        }

        return $this;
    }
public function add ( $ item , array $ tags = [ ] ) { if ( $ item instanceof RunInterface && ! ( $ this -> isRunning ( ) || $ this -> runInstantly ) && $ item -> isRunning ( ) ) { throw new NotRunningException ( "add: unable to add a running item when the pool has not started" ) ; } // special handling of child collections, a pool should only care about leaf nodes if ( $ item instanceof PoolInterface ) { $ item -> addListener ( PoolRunEvent :: POOL_RUN_ADDED , function ( PoolRunEvent $ event ) { $ this -> add ( $ event -> getRun ( ) ) ; } ) ; foreach ( $ item -> getAll ( ) as $ child ) { $ this -> add ( $ child ) ; } return $ this ; } parent :: add ( $ item , $ tags ) ; if ( $ item instanceof RunInterface && ! $ item -> hasStarted ( ) ) { $ this -> waitingQueue -> insert ( $ item , $ item -> getPriority ( ) ) ; if ( $ this -> runInstantly ) { $ this -> startNext ( ) ; } } if ( $ item instanceof PrioritisedInterface && $ item instanceof DispatcherInterface ) { $ item -> addListener ( PriorityChangedEvent :: CHANGED , [ $ this , 'onPriorityChanged' ] ) ; } return $ this ; }
Add a new process to the pool

@param RunInterface|PoolInterface|Process $item
@param array                              $tags If a process is supplied, these are added to create a run.
This is ignored when adding a run

@return $this
Add a new process to the pool