public function main() { @(include_once 'phing/contrib/DocBlox/Parallel/Manager.php'); @(include_once 'phing/contrib/DocBlox/Parallel/Worker.php'); @(include_once 'phing/contrib/DocBlox/Parallel/WorkerPipe.php'); if (!class_exists('DocBlox_Parallel_Worker')) { throw new BuildException('ParallelTask depends on DocBlox being installed and on include_path.', $this->getLocation()); } $mgr = new DocBlox_Parallel_Manager(); $mgr->setProcessLimit($this->threadCount); foreach ($this->nestedTasks as $task) { $worker = new DocBlox_Parallel_Worker(array($task, 'perform'), array($task)); $mgr->addWorker($worker); } $mgr->execute(); }
return 'c'; }))->addWorker(new DocBlox_Parallel_Worker(function () { sleep(1); return 'd'; }))->addWorker(new DocBlox_Parallel_Worker(function () { sleep(1); return 'e'; }))->execute(); /** @var DocBlox_Parallel_Worker $worker */ foreach ($mgr as $worker) { var_dump($worker->getResult()); } // ----------------------------------------------------------------------------- // method 2: using the manager as worker array // ----------------------------------------------------------------------------- $mgr = new DocBlox_Parallel_Manager(); $mgr[] = new DocBlox_Parallel_Worker(function () { sleep(1); return 'f'; }); $mgr[] = new DocBlox_Parallel_Worker(function () { sleep(1); return 'g'; }); $mgr[] = new DocBlox_Parallel_Worker(function () { sleep(1); return 'h'; }); $mgr[] = new DocBlox_Parallel_Worker(function () { sleep(1); return 'i';
/** * Processes a list of files & directories * * @param Task $callee * @param PhingFile $fromDir * @param array $srcFiles * @param array $srcDirs */ protected function process(DocBlox_Parallel_Manager $parallelManager, Task $callee, PhingFile $fromDir, $srcFiles, $srcDirs) { $mapper = null; if ($this->mapperElement !== null) { $mapper = $this->mapperElement->getImplementation(); } $filecount = count($srcFiles); $this->total_files += $filecount; for ($j = 0; $j < $filecount; $j++) { $value = $srcFiles[$j]; $premapped = ""; if ($this->absparam) { $prop = $callee->createProperty(); $prop->setOverride(true); $prop->setName($this->absparam); $prop->setValue($fromDir . FileSystem::getFileSystem()->getSeparator() . $value); } if ($mapper !== null) { $premapped = $value; $value = $mapper->main($value); if ($value === null) { continue; } $value = array_shift($value); } if ($this->param) { $this->log("Setting param '{$this->param}' to value '{$value}'" . ($premapped ? " (mapped from '{$premapped}')" : ''), Project::MSG_VERBOSE); $prop = $callee->createProperty(); $prop->setOverride(true); $prop->setName($this->param); $prop->setValue($value); } $worker = new DocBlox_Parallel_Worker(array($callee, 'main'), array($callee)); $parallelManager->addWorker($worker); } $dircount = count($srcDirs); $this->total_dirs += $dircount; for ($j = 0; $j < $dircount; $j++) { $value = $srcDirs[$j]; $premapped = ""; if ($this->absparam) { $prop = $callee->createProperty(); $prop->setOverride(true); $prop->setName($this->absparam); $prop->setValue($fromDir . FileSystem::getFileSystem()->getSeparator() . $value); } if ($mapper !== null) { $premapped = $value; $value = $mapper->main($value); if ($value === null) { continue; } $value = array_shift($value); } if ($this->param) { $this->log("Setting param '{$this->param}' to value '{$value}'" . ($premapped ? " (mapped from '{$premapped}')" : ''), Project::MSG_VERBOSE); $prop = $callee->createProperty(); $prop->setOverride(true); $prop->setName($this->param); $prop->setValue($value); } $worker = new DocBlox_Parallel_Worker(array($callee, 'main'), array($callee)); $parallelManager->addWorker($worker); } }