コード例 #1
0
 protected function spawnProcess()
 {
     $processOptions = isset($this->options['processOptions']) ? $this->options['processOptions'] : [];
     $process = clone $this->sourceProcess;
     Factory::parent($process, $this->loop, $processOptions)->then(function (Messenger $messenger) {
         Util::forwardEvents($messenger, $this, ['error']);
         $this->pool->attach($messenger);
         $this->readyPool->enqueue($messenger);
         $this->emit('messenger', [$messenger, $this]);
     }, function ($error) {
         $this->emit('error', [$error, $this]);
     });
 }
コード例 #2
0
 protected function spawnProcessAtAddress($address)
 {
     $this->startingProcesses++;
     unset($this->availableAddresses[$address]);
     $processOptions = isset($this->options['processOptions']) ? $this->options['processOptions'] : [];
     $process = $this->rebuildProcess($address);
     Factory::parent($process, $this->loop, $processOptions)->then(function (Messenger $messenger) use($address) {
         $this->startingProcesses--;
         $this->pool->attach($messenger);
         $this->readyPool->enqueue($messenger);
         $this->emit('messenger', [$messenger, $this]);
         $this->coreMessengerMapping[spl_object_hash($messenger)] = $address;
         $messenger->on('exit', function () use($messenger, $address) {
             $this->pool->detach($messenger);
             $this->availableAddresses[$address] = $address;
             unset($this->coreMessengerMapping[spl_object_hash($messenger)]);
             $messengers = [];
             while ($this->readyPool->count() > 0) {
                 $queuedMessenger = $this->readyPool->dequeue();
                 if ($queuedMessenger === $messenger) {
                     continue;
                 }
                 $messengers[] = $queuedMessenger;
             }
             array_walk($messengers, function (Messenger $messenger) {
                 $this->readyPool->enqueue($messenger);
             });
             if ($this->callQueue->count() > 0 && $this->readyPool->count() <= $this->options['min_size'] && $this->startingProcesses + $this->pool->count() < $this->options['max_size']) {
                 $this->spawnProcess();
             }
         });
     }, function ($error) {
         $this->startingProcesses--;
         $this->emit('error', [$error, $this]);
     });
 }
コード例 #3
0
 /**
  * @param LoopInterface $loop
  * @param array $options
  * @return PromiseInterface
  * @throws \Exception
  */
 public function __invoke(LoopInterface $loop, array $options)
 {
     return Factory::parent(clone $this->process, $loop, $options);
 }