Skip to content

Commit f168385

Browse files
committed
Drop $workerLimit param
1 parent 5b6d389 commit f168385

File tree

1 file changed

+6
-32
lines changed

1 file changed

+6
-32
lines changed

src/Driver/ParallelFilesystemDriver.php

Lines changed: 6 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -7,57 +7,31 @@
77
use Amp\File\Internal;
88
use Amp\Future;
99
use Amp\Parallel\Worker\ContextWorkerPool;
10-
use Amp\Parallel\Worker\DelegatingWorkerPool;
1110
use Amp\Parallel\Worker\LimitedWorkerPool;
1211
use Amp\Parallel\Worker\TaskFailureThrowable;
1312
use Amp\Parallel\Worker\Worker;
1413
use Amp\Parallel\Worker\WorkerException;
15-
use Amp\Parallel\Worker\WorkerPool;
1614
use function Amp\async;
1715

1816
final class ParallelFilesystemDriver implements FilesystemDriver
1917
{
2018
public const DEFAULT_WORKER_LIMIT = 8;
2119

22-
private readonly WorkerPool $pool;
23-
24-
/** @var positive-int Maximum number of workers to use for open files. */
25-
private readonly int $workerLimit;
26-
2720
/** @var \WeakMap<Worker, int> */
2821
private \WeakMap $workerStorage;
2922

3023
/** @var Future<Worker>|null Pending worker request */
3124
private ?Future $pendingWorker = null;
3225

3326
/**
34-
* @param WorkerPool|null $pool Custom worker pool to use for file workers. If null, a new pool is created.
35-
* @param int|null $workerLimit [Deprecated] Maximum number of workers to use from the pool for open files. Instead
36-
* of using this parameter, provide a pool with a limited number using an instance of {@see LimitedWorkerPool}
37-
* such as {@see ContextWorkerPool}.
27+
* @param LimitedWorkerPool $pool Custom worker pool to use for file workers. If one is not provided, a new
28+
* pool is created.
3829
*/
39-
public function __construct(?WorkerPool $pool = null, ?int $workerLimit = null)
40-
{
30+
public function __construct(
31+
private readonly LimitedWorkerPool $pool = new ContextWorkerPool(self::DEFAULT_WORKER_LIMIT),
32+
) {
4133
/** @var \WeakMap<Worker, int> For Psalm. */
4234
$this->workerStorage = new \WeakMap();
43-
44-
if ($workerLimit !== null) {
45-
\trigger_error(
46-
'The $workerLimit parameter is deprecated and will be removed in the next major version.' .
47-
' To limit the number of workers used from the given pool, use an instance of ' .
48-
LimitedWorkerPool::class . ' instead, such as ' . ContextWorkerPool::class . ' or ' .
49-
DelegatingWorkerPool::class,
50-
\E_USER_DEPRECATED,
51-
);
52-
}
53-
54-
$workerLimit ??= $pool instanceof LimitedWorkerPool ? $pool->getWorkerLimit() : self::DEFAULT_WORKER_LIMIT;
55-
if ($workerLimit <= 0) {
56-
throw new \ValueError("Worker limit must be a positive integer");
57-
}
58-
59-
$this->pool = $pool ?? new ContextWorkerPool($workerLimit);
60-
$this->workerLimit = $workerLimit;
6135
}
6236

6337
public function openFile(string $path, string $mode): ParallelFile
@@ -90,7 +64,7 @@ private function selectWorker(): Worker
9064
{
9165
$this->pendingWorker?->await(); // Wait for any currently pending request for a worker.
9266

93-
if ($this->workerStorage->count() < $this->workerLimit) {
67+
if ($this->workerStorage->count() < $this->pool->getWorkerLimit()) {
9468
$this->pendingWorker = async($this->pool->getWorker(...));
9569
$worker = $this->pendingWorker->await();
9670

0 commit comments

Comments
 (0)