Commit 05ece13 1 parent feed27e commit 05ece13 Copy full SHA for 05ece13
File tree 3 files changed +29
-4
lines changed
3 files changed +29
-4
lines changed Original file line number Diff line number Diff line change 20
20
* tasks simultaneously. The load on each worker is balanced such that tasks
21
21
* are completed as soon as possible and workers are used efficiently.
22
22
*/
23
- final class ContextWorkerPool implements WorkerPool
23
+ final class ContextWorkerPool implements LimitedWorkerPool
24
24
{
25
25
use ForbidCloning;
26
26
use ForbidSerialization;
@@ -104,14 +104,21 @@ public function isIdle(): bool
104
104
return $ this ->idleWorkers ->count () > 0 || $ this ->workers ->count () < $ this ->limit ;
105
105
}
106
106
107
+ public function getWorkerLimit (): int
108
+ {
109
+ return $ this ->limit ;
110
+ }
111
+
107
112
/**
108
113
* Gets the maximum number of workers the pool may spawn to handle concurrent tasks.
109
114
*
110
115
* @return int The maximum number of workers.
116
+ *
117
+ * @deprecated Use {@see getWorkerLimit()} instead.
111
118
*/
112
119
public function getLimit (): int
113
120
{
114
- return $ this ->limit ;
121
+ return $ this ->getWorkerLimit () ;
115
122
}
116
123
117
124
public function getWorkerCount (): int
Original file line number Diff line number Diff line change 4
4
5
5
use Amp \Cancellation ;
6
6
use Amp \DeferredFuture ;
7
+ use Amp \ForbidCloning ;
8
+ use Amp \ForbidSerialization ;
7
9
use Amp \Parallel \Worker \Internal \PooledWorker ;
8
10
9
- final class DelegatingWorkerPool implements WorkerPool
11
+ final class DelegatingWorkerPool implements LimitedWorkerPool
10
12
{
13
+ use ForbidCloning;
14
+ use ForbidSerialization;
15
+
11
16
/** @var array<int, Worker> */
12
17
private array $ workerStorage = [];
13
18
@@ -116,7 +121,7 @@ public function getWorker(): Worker
116
121
return new PooledWorker ($ this ->selectWorker (), $ this ->push (...));
117
122
}
118
123
119
- public function getLimit (): int
124
+ public function getWorkerLimit (): int
120
125
{
121
126
return $ this ->limit ;
122
127
}
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