protected function spawn()
 {
     $this->startingProcesses++;
     $current = $this->processCollection->current();
     $promise = $current($this->loop, $this->options);
     $promise->then(function (Messenger $messenger) {
         $worker = new Worker($messenger);
         $this->workers[] = $worker;
         $worker->on('done', function (WorkerInterface $worker) {
             $this->workerAvailable($worker);
         });
         $worker->on('terminating', function (WorkerInterface $worker) {
             foreach ($this->workers as $key => $value) {
                 if ($worker === $value) {
                     unset($this->workers[$key]);
                     break;
                 }
             }
         });
         $this->workerAvailable($worker);
         $this->startingProcesses--;
     });
     $this->processCollection->next();
     if (!$this->processCollection->valid()) {
         $this->processCollection->rewind();
     }
 }
 public function __construct(ProcessCollectionInterface $processCollection, LoopInterface $loop, array $options = [])
 {
     $this->loop = $loop;
     $processCollection->rewind();
     for ($i = 0; $i < $options[Options::SIZE]; $i++) {
         $this->spawn($processCollection, $options);
     }
 }