original_string: private function runTask(array $hosts, Task $task): int
      {
          $processes = [];
  
          foreach ($hosts as $host) {
              if ($task->shouldBePerformed($host)) {
                  $processes[$host->getHostname()] = $this->getProcess($host, $task);
                  if ($task->isOnce()) {
                      $task->setHasRun();
                  }
              }
          }
  
          $callback = function (string $type, string $host, string $output) {
              $output = rtrim($output);
              if (strlen($output) !== 0) {
                  $this->output->writeln($output);
              }
          };
  
          $this->startProcesses($processes);
  
          while ($this->areRunning($processes)) {
              $this->gatherOutput($processes, $callback);
              usleep(1000);
          }
          $this->gatherOutput($processes, $callback);
  
          return $this->gatherExitCodes($processes);
      }
code: private function runTask(array $hosts, Task $task): int
      {
          $processes = [];
  
          foreach ($hosts as $host) {
              if ($task->shouldBePerformed($host)) {
                  $processes[$host->getHostname()] = $this->getProcess($host, $task);
                  if ($task->isOnce()) {
                      $task->setHasRun();
                  }
              }
          }
  
          $callback = function (string $type, string $host, string $output) {
              $output = rtrim($output);
              if (strlen($output) !== 0) {
                  $this->output->writeln($output);
              }
          };
  
          $this->startProcesses($processes);
  
          while ($this->areRunning($processes)) {
              $this->gatherOutput($processes, $callback);
              usleep(1000);
          }
          $this->gatherOutput($processes, $callback);
  
          return $this->gatherExitCodes($processes);
      }
code_tokens: private function runTask ( array $ hosts , Task $ task ) : int { $ processes = [ ] ; foreach ( $ hosts as $ host ) { if ( $ task -> shouldBePerformed ( $ host ) ) { $ processes [ $ host -> getHostname ( ) ] = $ this -> getProcess ( $ host , $ task ) ; if ( $ task -> isOnce ( ) ) { $ task -> setHasRun ( ) ; } } } $ callback = function ( string $ type , string $ host , string $ output ) { $ output = rtrim ( $ output ) ; if ( strlen ( $ output ) !== 0 ) { $ this -> output -> writeln ( $ output ) ; } } ; $ this -> startProcesses ( $ processes ) ; while ( $ this -> areRunning ( $ processes ) ) { $ this -> gatherOutput ( $ processes , $ callback ) ; usleep ( 1000 ) ; } $ this -> gatherOutput ( $ processes , $ callback ) ; return $ this -> gatherExitCodes ( $ processes ) ; }
docstring: Run task on hosts.
  
  @param Host[] $hosts
docstring_tokens: Run task on hosts .