1
0
mirror of https://github.com/danog/parallel.git synced 2024-11-26 20:34:40 +01:00

Use default sizes as default values

This commit is contained in:
Aaron Piotrowski 2017-12-12 21:39:51 -06:00
parent 91314f13f6
commit cb87b1cd9a
No known key found for this signature in database
GPG Key ID: ADD1EF783EDE9EEB
4 changed files with 13 additions and 9 deletions

View File

@ -43,19 +43,20 @@ class DefaultPool implements Pool {
/**
* Creates a new worker pool.
*
* @param int|null $minSize The minimum number of workers the pool should spawn.
* @param int $minSize The minimum number of workers the pool should spawn.
* Defaults to `Pool::DEFAULT_MIN_SIZE`.
* @param int|null $maxSize The maximum number of workers the pool should spawn.
* @param int $maxSize The maximum number of workers the pool should spawn.
* Defaults to `Pool::DEFAULT_MAX_SIZE`.
* @param \Amp\Parallel\Worker\WorkerFactory|null $factory A worker factory to be used to create
* new workers.
*
* @throws \Error
*/
public function __construct(int $minSize = null, int $maxSize = null, WorkerFactory $factory = null) {
$minSize = $minSize ?: self::DEFAULT_MIN_SIZE;
$maxSize = $maxSize ?: self::DEFAULT_MAX_SIZE;
public function __construct(
int $minSize = self::DEFAULT_MIN_SIZE,
int $maxSize = self::DEFAULT_MAX_SIZE,
WorkerFactory $factory = null
) {
if ($minSize < 0) {
throw new \Error('Minimum size must be a non-negative integer.');
}

View File

@ -3,6 +3,7 @@
namespace Amp\Parallel\Test\Worker;
use Amp\Loop;
use Amp\Parallel\Worker\Pool;
use Amp\PHPUnit\TestCase;
abstract class AbstractPoolTest extends TestCase {
@ -12,7 +13,7 @@ abstract class AbstractPoolTest extends TestCase {
*
* @return \Amp\Parallel\Worker\Pool
*/
abstract protected function createPool($min = null, $max = null);
abstract protected function createPool($min = null, $max = null): Pool;
public function testIsRunning() {
Loop::run(function () {

View File

@ -3,6 +3,7 @@
namespace Amp\Parallel\Test\Worker;
use Amp\Parallel\Worker\DefaultPool;
use Amp\Parallel\Worker\Pool;
use Amp\Parallel\Worker\WorkerFactory;
use Amp\Parallel\Worker\WorkerProcess;
@ -10,7 +11,7 @@ use Amp\Parallel\Worker\WorkerProcess;
* @group process
*/
class ProcessPoolTest extends AbstractPoolTest {
protected function createPool($min = null, $max = null) {
protected function createPool($min = Pool::DEFAULT_MIN_SIZE, $max =Pool::DEFAULT_MAX_SIZE): Pool {
$factory = $this->createMock(WorkerFactory::class);
$factory->method('create')->will($this->returnCallback(function () {
return new WorkerProcess;

View File

@ -3,6 +3,7 @@
namespace Amp\Parallel\Test\Worker;
use Amp\Parallel\Worker\DefaultPool;
use Amp\Parallel\Worker\Pool;
use Amp\Parallel\Worker\WorkerFactory;
use Amp\Parallel\Worker\WorkerThread;
@ -11,7 +12,7 @@ use Amp\Parallel\Worker\WorkerThread;
* @requires extension pthreads
*/
class ThreadPoolTest extends AbstractPoolTest {
protected function createPool($min = null, $max = null) {
protected function createPool($min = Pool::DEFAULT_MIN_SIZE, $max = Pool::DEFAULT_MAX_SIZE): Pool {
$factory = $this->createMock(WorkerFactory::class);
$factory->method('create')->will($this->returnCallback(function () {
return new WorkerThread;