1
0
mirror of https://github.com/danog/parallel.git synced 2024-11-30 04:39:01 +01:00

Set global pool size directly

This commit is contained in:
coderstephen 2015-08-28 12:04:04 -05:00
parent 65f17be82e
commit e80cd2818d
2 changed files with 13 additions and 9 deletions

View File

@ -140,10 +140,8 @@ class WorkerPool
*/
public function enqueue(TaskInterface $task)
{
$worker = $this->getIdleWorker();
// Enqueue the task if we have an idle worker.
if ($worker) {
if ($worker = $this->getIdleWorker()) {
yield $this->enqueueToWorker($task, $worker);
return;
}

View File

@ -5,18 +5,24 @@ if (!function_exists(__NAMESPACE__ . '\pool')) {
/**
* Returns the default worker pool for the current context.
*
* @param WorkerPool $pool The instance to use as the default worker pool.
* If the pool has not been initialized, a minimum and maximum size can be given to create the pool with.
*
* @param int|null $minSize The minimum number of workers the pool should spawn.
* @param int|null $maxSize The maximum number of workers the pool should spawn.
* @param WorkerFactoryInterface|null $factory A worker factory to be used to create new workers.
*
* @return WorkerPool
*/
function pool(WorkerPool $pool = null)
function pool($minSize = null, $maxSize = null, WorkerFactoryInterface $factory = null)
{
static $instance;
if (null !== $pool) {
$instance = $pool;
} elseif (null === $instance) {
$instance = new WorkerPool(4, 16);
if (null === $instance) {
if (null !== $minSize) {
$instance = new WorkerPool($minSize, $maxSize, $factory);
} else {
$instance = new WorkerPool(8, 32);
}
}
return $instance;