Skip to content

AsyncPool ​

class · pocketmine\scheduler\AsyncPool · source

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

Properties ​

$size ​

php
public int $size

Methods ​

__construct() ​

php
public function __construct(int $size, int $workerMemoryLimit, \pocketmine\thread\ThreadSafeClassLoader $classLoader, \pocketmine\thread\log\ThreadSafeLogger $logger, \pocketmine\snooze\SleeperHandler $eventLoop)

addWorkerStartHook() ​

php
public function addWorkerStartHook(\Closure $hook) : void

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.

collectTasks() ​

php
public function collectTasks() : bool

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

collectTasksFromWorker() ​

php
public function collectTasksFromWorker(int $worker) : bool

getRunningWorkers() ​

php
public function getRunningWorkers() : array

Returns an array of IDs of currently running workers.

getSize() ​

php
public function getSize() : int

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

getTaskQueueSizes() ​

php
public function getTaskQueueSizes() : array

Returns an array of worker ID => task queue size

increaseSize() ​

php
public function increaseSize(int $newSize) : void

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

removeWorkerStartHook() ​

php
public function removeWorkerStartHook(\Closure $hook) : void

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

selectWorker() ​

php
public function selectWorker() : int

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.

shutdown() ​

php
public function shutdown() : void

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

shutdownUnusedWorkers() ​

php
public function shutdownUnusedWorkers() : int

submitTask() ​

php
public function submitTask(\pocketmine\scheduler\AsyncTask $task) : int

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.

submitTaskToWorker() ​

php
public function submitTaskToWorker(\pocketmine\scheduler\AsyncTask $task, int $worker) : void

Submits an AsyncTask to an arbitrary worker.

VanillaMine is a fork of PocketMine-MP, maintained by Luxury Nodes. Not affiliated with the PMMP team or Mojang.