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:
parent
91314f13f6
commit
cb87b1cd9a
@ -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.');
|
||||
}
|
||||
|
@ -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 () {
|
||||
|
@ -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;
|
||||
|
@ -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;
|
||||
|
Loading…
Reference in New Issue
Block a user