Skip to content

Commit

Permalink
add several pool methods
Browse files Browse the repository at this point in the history
  • Loading branch information
white-poto committed Feb 10, 2017
1 parent 4d934e0 commit 6397ddc
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 37 deletions.
67 changes: 67 additions & 0 deletions src/AbstractPool.php
Original file line number Diff line number Diff line change
Expand Up @@ -113,4 +113,71 @@ public function aliveCount()

return $count;
}

/**
* get process by name
*
* @param string $name process name
* @return Process|null
*/
public function getProcessByName($name)
{
foreach ($this->processes as $process) {
if ($process->name() == $name) {
return $process;
}
}

return null;
}

/**
* remove process by name
*
* @param string $name process name
* @throws \RuntimeException
*/
public function removeProcessByName($name)
{
foreach ($this->processes as $key => $process) {
if ($process->name() == $name) {
if ($process->isRunning()) {
throw new \RuntimeException("can not remove a running process");
}
unset($this->processes[$key]);
}
}
}

/**
* remove exited process
*/
public function removeExitedProcess()
{
foreach ($this->processes as $key => $process) {
if ($process->isStopped()) {
unset($this->processes[$key]);
}
}
}

/**
* return process count
*
* @return int
*/
public function count()
{
return count($this->processes);
}

/**
* get all processes
*
* @return Process[]
*/
public function getProcesses()
{
return $this->processes;
}
}
20 changes: 0 additions & 20 deletions src/ParallelPool.php
Original file line number Diff line number Diff line change
Expand Up @@ -103,24 +103,4 @@ public function start()
}
}
}

/**
* return process count
*
* @return int
*/
public function count()
{
return count($this->processes);
}

/**
* get all processes
*
* @return Process[]
*/
public function getProcesses()
{
return $this->processes;
}
}
17 changes: 0 additions & 17 deletions src/Pool.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,21 +35,4 @@ public function execute(Process $process, $name = null)

return array_push($this->processes, $process);
}

/**
* get process by name
*
* @param string $name process name
* @return Process|null
*/
public function getProcessByName($name)
{
foreach ($this->processes as $process) {
if ($process->name() == $name) {
return $process;
}
}

return null;
}
}

0 comments on commit 6397ddc

Please sign in to comment.