1
0
mirror of https://github.com/danog/parallel.git synced 2025-01-22 14:01:14 +01:00

Gut lame factories

This commit is contained in:
Stephen Coakley 2015-12-11 23:28:44 -06:00
parent 5970597a59
commit 347132825e
6 changed files with 16 additions and 55 deletions

View File

@ -3,9 +3,6 @@ All notable changes to this project will be documented in this file. This projec
## Unreleased ## Unreleased
### Added
- You can now easily create worker pools that use a fixed worker type with new dedicated worker factories: `Worker\WorkerThreadFactory`, `Worker\WorkerForkFactory`, and `Worker\WorkerProcessFactory`.
### Changed ### Changed
- Updated to Icicle `0.9.x` packages. - Updated to Icicle `0.9.x` packages.

View File

@ -1,16 +0,0 @@
<?php
namespace Icicle\Concurrent\Worker;
/**
* Worker factory for creating worker forks.
*/
class WorkerForkFactory implements WorkerFactory
{
/**
* {@inheritdoc}
*/
public function create()
{
return new WorkerFork();
}
}

View File

@ -1,16 +0,0 @@
<?php
namespace Icicle\Concurrent\Worker;
/**
* Worker factory for creating worker processes.
*/
class WorkerProcessFactory implements WorkerFactory
{
/**
* {@inheritdoc}
*/
public function create()
{
return new WorkerProcess();
}
}

View File

@ -1,16 +0,0 @@
<?php
namespace Icicle\Concurrent\Worker;
/**
* Worker factory for creating worker threads.
*/
class WorkerThreadFactory implements WorkerFactory
{
/**
* {@inheritdoc}
*/
public function create()
{
return new WorkerThread();
}
}

View File

@ -2,7 +2,8 @@
namespace Icicle\Tests\Concurrent\Worker; namespace Icicle\Tests\Concurrent\Worker;
use Icicle\Concurrent\Worker\DefaultPool; use Icicle\Concurrent\Worker\DefaultPool;
use Icicle\Concurrent\Worker\WorkerForkFactory; use Icicle\Concurrent\Worker\WorkerFactory;
use Icicle\Concurrent\Worker\WorkerFork;
/** /**
* @group forking * @group forking
@ -12,6 +13,11 @@ class ForkPoolTest extends AbstractPoolTest
{ {
protected function createPool($min = null, $max = null) protected function createPool($min = null, $max = null)
{ {
return new DefaultPool($min, $max, new WorkerForkFactory()); $factory = $this->getMock(WorkerFactory::class);
$factory->method('create')->will($this->returnCallback(function () {
return new WorkerFork();
}));
return new DefaultPool($min, $max, $factory);
} }
} }

View File

@ -2,7 +2,8 @@
namespace Icicle\Tests\Concurrent\Worker; namespace Icicle\Tests\Concurrent\Worker;
use Icicle\Concurrent\Worker\DefaultPool; use Icicle\Concurrent\Worker\DefaultPool;
use Icicle\Concurrent\Worker\WorkerThreadFactory; use Icicle\Concurrent\Worker\WorkerFactory;
use Icicle\Concurrent\Worker\WorkerThread;
/** /**
* @group threading * @group threading
@ -12,6 +13,11 @@ class ThreadPoolTest extends AbstractPoolTest
{ {
protected function createPool($min = null, $max = null) protected function createPool($min = null, $max = null)
{ {
return new DefaultPool($min, $max, new WorkerThreadFactory()); $factory = $this->getMock(WorkerFactory::class);
$factory->method('create')->will($this->returnCallback(function () {
return new WorkerThread();
}));
return new DefaultPool($min, $max, $factory);
} }
} }