AsyncPool
Manages general-purpose worker threads used for processing asynchronous tasks, and the tasks submitted to those workers.
Properties
$size
public int $sizeMethods
__construct()
public function __construct(int $size, int $workerMemoryLimit, \pocketmine\thread\ThreadSafeClassLoader $classLoader, \pocketmine\thread\log\ThreadSafeLogger $logger, \pocketmine\snooze\SleeperHandler $eventLoop)addWorkerStartHook()
public function addWorkerStartHook(\Closure $hook) : voidRegisters 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()
public function collectTasks() : boolCollects finished and/or crashed tasks from the workers, firing their on-completion hooks where appropriate.
collectTasksFromWorker()
public function collectTasksFromWorker(int $worker) : boolgetRunningWorkers()
public function getRunningWorkers() : arrayReturns an array of IDs of currently running workers.
getSize()
public function getSize() : intReturns the maximum size of the pool. Note that there may be less active workers than this number.
getTaskQueueSizes()
public function getTaskQueueSizes() : arrayReturns an array of worker ID => task queue size
increaseSize()
public function increaseSize(int $newSize) : voidIncreases the maximum size of the pool to the specified amount. This does not immediately start new workers.
removeWorkerStartHook()
public function removeWorkerStartHook(\Closure $hook) : voidRemoves a previously-registered callback listening for workers being started.
selectWorker()
public function selectWorker() : intSelects 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()
public function shutdown() : voidCancels all pending tasks and shuts down all the workers in the pool.
shutdownUnusedWorkers()
public function shutdownUnusedWorkers() : intsubmitTask()
public function submitTask(\pocketmine\scheduler\AsyncTask $task) : intSubmits 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()
public function submitTaskToWorker(\pocketmine\scheduler\AsyncTask $task, int $worker) : voidSubmits an AsyncTask to an arbitrary worker.
