Amp\Parallel\Worker\DefaultPool classDefaultPool implementsAmp\Parallel\Worker\Pool

Provides a pool of workers that can be used to execute multiple tasks asynchronously.

A worker pool is a collection of worker threads that can perform multiple tasks simultaneously. The load on each worker is balanced such that tasks are completed as soon as possible and workers are used efficiently.

Summary

Properties

Methods

Properties

Methods

__construct —public function__construct(int$maxSize =self::DEFAULT_MAX_SIZE,Amp\Parallel\Worker\WorkerFactory|null$factory =null)

Creates a new worker pool.

Type Parameter Description Default Value
int $maxSize The maximum number of workers the pool should spawn. Defaults to `Pool::DEFAULT_MAX_SIZE`. self::DEFAULT_MAX_SIZE
Amp\Parallel\Worker\WorkerFactory|null $factory A worker factory to be used to create new workers. null
isRunning —public functionisRunning():bool

Checks if the pool is running.

isIdle —public functionisIdle():bool

Checks if the pool has any idle workers.

getMaxSize —public functiongetMaxSize():int

Gets the maximum number of workers the pool may spawn to handle concurrent tasks.

getWorkerCount —public functiongetWorkerCount():int

Gets the number of workers currently running in the pool.

getIdleWorkerCount —public functiongetIdleWorkerCount():int

Gets the number of workers that are currently idle.

enqueue —public functionenqueue(Amp\Parallel\Worker\Task$task):Amp\Promise
No documentation.
Type Parameter Description Default Value
Amp\Parallel\Worker\Task $task No documentation. none
shutdown —public functionshutdown():Amp\Promise
No documentation.
kill —public functionkill()

Kills all workers in the pool and halts the worker pool.

get —public functionget():Amp\Parallel\Worker\Worker

Gets a worker from the pool. The worker is marked as busy and will only be reused if the pool runs out of idle workers. The worker will be automatically marked as idle once no references to the returned worker remain.

pull —protected functionpull():Amp\Parallel\Worker\Worker

Pulls a worker from the pool. The worker should be put back into the pool with push() to be marked as idle.

push —protected functionpush(Amp\Parallel\Worker\Worker$worker)

Pushes the worker back into the pool and mark it as idle.

Type Parameter Description Default Value
Amp\Parallel\Worker\Worker $worker No documentation. none