File tree Expand file tree Collapse file tree 3 files changed +29
-4
lines changed
Expand file tree Collapse file tree 3 files changed +29
-4
lines changed Original file line number Diff line number Diff line change 2020 * tasks simultaneously. The load on each worker is balanced such that tasks
2121 * are completed as soon as possible and workers are used efficiently.
2222 */
23- final class ContextWorkerPool implements WorkerPool
23+ final class ContextWorkerPool implements LimitedWorkerPool
2424{
2525 use ForbidCloning;
2626 use ForbidSerialization;
@@ -104,14 +104,21 @@ public function isIdle(): bool
104104 return $ this ->idleWorkers ->count () > 0 || $ this ->workers ->count () < $ this ->limit ;
105105 }
106106
107+ public function getWorkerLimit (): int
108+ {
109+ return $ this ->limit ;
110+ }
111+
107112 /**
108113 * Gets the maximum number of workers the pool may spawn to handle concurrent tasks.
109114 *
110115 * @return int The maximum number of workers.
116+ *
117+ * @deprecated Use {@see getWorkerLimit()} instead.
111118 */
112119 public function getLimit (): int
113120 {
114- return $ this ->limit ;
121+ return $ this ->getWorkerLimit () ;
115122 }
116123
117124 public function getWorkerCount (): int
Original file line number Diff line number Diff line change 44
55use Amp \Cancellation ;
66use Amp \DeferredFuture ;
7+ use Amp \ForbidCloning ;
8+ use Amp \ForbidSerialization ;
79use Amp \Parallel \Worker \Internal \PooledWorker ;
810
9- final class DelegatingWorkerPool implements WorkerPool
11+ final class DelegatingWorkerPool implements LimitedWorkerPool
1012{
13+ use ForbidCloning;
14+ use ForbidSerialization;
15+
1116 /** @var array<int, Worker> */
1217 private array $ workerStorage = [];
1318
@@ -116,7 +121,7 @@ public function getWorker(): Worker
116121 return new PooledWorker ($ this ->selectWorker (), $ this ->push (...));
117122 }
118123
119- public function getLimit (): int
124+ public function getWorkerLimit (): int
120125 {
121126 return $ this ->limit ;
122127 }
Original file line number Diff line number Diff line change 1+ <?php declare (strict_types=1 );
2+
3+ namespace Amp \Parallel \Worker ;
4+
5+ interface LimitedWorkerPool extends WorkerPool
6+ {
7+ /**
8+ * Gets the maximum number of workers the pool may spawn to handle concurrent tasks.
9+ *
10+ * @return int The maximum number of workers.
11+ */
12+ public function getWorkerLimit (): int ;
13+ }
You can’t perform that action at this time.
0 commit comments