PocketMine-MP 5.15.1 git-be6754494fdbbb9dd57c058ba0e33a4a78c4581f
pocketmine\scheduler\AsyncPool Class Reference
+ Collaboration diagram for pocketmine\scheduler\AsyncPool:

Public Member Functions

 __construct (protected int $size, private int $workerMemoryLimit, private ThreadSafeClassLoader $classLoader, private ThreadSafeLogger $logger, private SleeperHandler $eventLoop)
 
 addWorkerStartHook (\Closure $hook)
 
 collectTasks ()
 
 collectTasksFromWorker (int $worker)
 
 getRunningWorkers ()
 
 getSize ()
 
 getTaskQueueSizes ()
 
 increaseSize (int $newSize)
 
 removeWorkerStartHook (\Closure $hook)
 
 selectWorker ()
 
 shutdown ()
 
 shutdownUnusedWorkers ()
 
 submitTask (AsyncTask $task)
 
 submitTaskToWorker (AsyncTask $task, int $worker)
 

Detailed Description

Manages general-purpose worker threads used for processing asynchronous tasks, and the tasks submitted to those workers.

Definition at line 47 of file AsyncPool.php.

Constructor & Destructor Documentation

◆ __construct()

pocketmine\scheduler\AsyncPool::__construct ( protected int  $size,
private int  $workerMemoryLimit,
private ThreadSafeClassLoader  $classLoader,
private ThreadSafeLogger  $logger,
private SleeperHandler  $eventLoop 
)

Definition at line 62 of file AsyncPool.php.

Member Function Documentation

◆ addWorkerStartHook()

pocketmine\scheduler\AsyncPool::addWorkerStartHook ( \Closure  $hook)

Registers a Closure callback to be fired whenever a new worker is started by the pool. The signature should be function(int $worker) : void

This function will call the hook for every already-running worker.

@phpstan-param \Closure(int $workerId) : void $hook

Definition at line 94 of file AsyncPool.php.

◆ collectTasks()

pocketmine\scheduler\AsyncPool::collectTasks ( )

Collects finished and/or crashed tasks from the workers, firing their on-completion hooks where appropriate.

Exceptions

ReflectionException

Returns
bool whether there are tasks left to be collected

Definition at line 239 of file AsyncPool.php.

◆ collectTasksFromWorker()

pocketmine\scheduler\AsyncPool::collectTasksFromWorker ( int  $worker)

Definition at line 253 of file AsyncPool.php.

◆ getRunningWorkers()

pocketmine\scheduler\AsyncPool::getRunningWorkers ( )

Returns an array of IDs of currently running workers.

Returns
int[]

Definition at line 116 of file AsyncPool.php.

◆ getSize()

pocketmine\scheduler\AsyncPool::getSize ( )

Returns the maximum size of the pool. Note that there may be less active workers than this number.

Definition at line 73 of file AsyncPool.php.

◆ getTaskQueueSizes()

pocketmine\scheduler\AsyncPool::getTaskQueueSizes ( )

Returns an array of worker ID => task queue size

Returns
int[] @phpstan-return array<int, int>

Definition at line 299 of file AsyncPool.php.

◆ increaseSize()

pocketmine\scheduler\AsyncPool::increaseSize ( int  $newSize)

Increases the maximum size of the pool to the specified amount. This does not immediately start new workers.

Definition at line 80 of file AsyncPool.php.

◆ removeWorkerStartHook()

pocketmine\scheduler\AsyncPool::removeWorkerStartHook ( \Closure  $hook)

Removes a previously-registered callback listening for workers being started.

@phpstan-param \Closure(int $workerId) : void $hook

Definition at line 107 of file AsyncPool.php.

Referenced by pocketmine\world\World\__construct().

+ Here is the caller graph for this function:

◆ selectWorker()

pocketmine\scheduler\AsyncPool::selectWorker ( )

Selects a worker ID to run a task.

  • if an idle worker is found, it will be selected
  • else, if the worker pool is not full, a new worker will be selected
  • else, the worker with the smallest backlog is chosen.

Definition at line 166 of file AsyncPool.php.

◆ shutdown()

pocketmine\scheduler\AsyncPool::shutdown ( )

Cancels all pending tasks and shuts down all the workers in the pool.

Definition at line 321 of file AsyncPool.php.

◆ shutdownUnusedWorkers()

pocketmine\scheduler\AsyncPool::shutdownUnusedWorkers ( )

Definition at line 303 of file AsyncPool.php.

◆ submitTask()

pocketmine\scheduler\AsyncPool::submitTask ( AsyncTask  $task)

Submits an AsyncTask to the worker with the least load. If all workers are busy and the pool is not full, a new worker may be started.

Definition at line 196 of file AsyncPool.php.

◆ submitTaskToWorker()

pocketmine\scheduler\AsyncPool::submitTaskToWorker ( AsyncTask  $task,
int  $worker 
)

Submits an AsyncTask to an arbitrary worker.

Definition at line 146 of file AsyncPool.php.


The documentation for this class was generated from the following file: