InvokedProcessPool.php
TLDR
This file defines the InvokedProcessPool
class, which represents a pool of invoked processes. It provides methods for sending a signal to the running processes, getting the currently running processes, waiting for the processes to finish, and getting the total number of processes in the pool.
Classes
InvokedProcessPool
The InvokedProcessPool
class represents a pool of invoked processes. It implements Countable
, allowing the count of processes to be retrieved. The class has the following methods:
signal
Sends a signal to each running process in the pool and returns the processes that were signalled. The method accepts an integer $signal
as a parameter.
running
Returns a collection of the processes in the pool that are currently still running.
wait
Waits for the processes in the pool to finish and returns a ProcessPoolResults
object representing the results.
count
Returns the total number of processes in the pool as an integer.
<?php
namespace Illuminate\Process;
use Countable;
class InvokedProcessPool implements Countable
{
/**
* The array of invoked processes.
*
* @var array
*/
protected $invokedProcesses;
/**
* Create a new invoked process pool.
*
* @param array $invokedProcesses
* @return void
*/
public function __construct(array $invokedProcesses)
{
$this->invokedProcesses = $invokedProcesses;
}
/**
* Send a signal to each running process in the pool, returning the processes that were signalled.
*
* @param int $signal
* @return \Illuminate\Support\Collection
*/
public function signal(int $signal)
{
return $this->running()->each->signal($signal);
}
/**
* Get the processes in the pool that are still currently running.
*
* @return \Illuminate\Support\Collection
*/
public function running()
{
return collect($this->invokedProcesses)->filter->running()->values();
}
/**
* Wait for the processes to finish.
*
* @return \Illuminate\Process\ProcessPoolResults
*/
public function wait()
{
return new ProcessPoolResults(collect($this->invokedProcesses)->map->wait()->all());
}
/**
* Get the total number of processes.
*
* @return int
*/
public function count(): int
{
return count($this->invokedProcesses);
}
}