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:
parent
5970597a59
commit
347132825e
@ -3,9 +3,6 @@ All notable changes to this project will be documented in this file. This projec
|
||||
|
||||
|
||||
## 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
|
||||
- Updated to Icicle `0.9.x` packages.
|
||||
|
||||
|
@ -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();
|
||||
}
|
||||
}
|
@ -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();
|
||||
}
|
||||
}
|
@ -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();
|
||||
}
|
||||
}
|
@ -2,7 +2,8 @@
|
||||
namespace Icicle\Tests\Concurrent\Worker;
|
||||
|
||||
use Icicle\Concurrent\Worker\DefaultPool;
|
||||
use Icicle\Concurrent\Worker\WorkerForkFactory;
|
||||
use Icicle\Concurrent\Worker\WorkerFactory;
|
||||
use Icicle\Concurrent\Worker\WorkerFork;
|
||||
|
||||
/**
|
||||
* @group forking
|
||||
@ -12,6 +13,11 @@ class ForkPoolTest extends AbstractPoolTest
|
||||
{
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
@ -2,7 +2,8 @@
|
||||
namespace Icicle\Tests\Concurrent\Worker;
|
||||
|
||||
use Icicle\Concurrent\Worker\DefaultPool;
|
||||
use Icicle\Concurrent\Worker\WorkerThreadFactory;
|
||||
use Icicle\Concurrent\Worker\WorkerFactory;
|
||||
use Icicle\Concurrent\Worker\WorkerThread;
|
||||
|
||||
/**
|
||||
* @group threading
|
||||
@ -12,6 +13,11 @@ class ThreadPoolTest extends AbstractPoolTest
|
||||
{
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user