Worker
extends Worker
in package
Uses
CommonThreadPartsTrait
Specialized Worker class for PocketMine-MP-related use cases. It handles setting up autoloading and error handling.
Workers are a special type of thread which execute tasks passed to them during their lifetime. Since creating a new thread has a high resource cost, workers can be kept around and reused for lots of short-lived tasks.
As a plugin developer, you'll rarely (if ever) actually need to use this class directly. If you want to run tasks on other CPU cores, check out AsyncTask first.
Tags
Table of Contents
- $composerAutoloaderPath : string|null
- $isKilled : bool
- $classLoaders : Threaded|null
- getClassLoaders() : array<string|int, ClassLoader>
- getThreadName() : string
- quit() : void
- Stops the thread using the best way possible. Try to stop it yourself before calling this.
- registerClassLoaders() : void
- Registers the class loaders for this thread.
- run() : void
- setClassLoaders() : void
- start() : bool
- onRun() : void
- Runs code on the thread.
Properties
$composerAutoloaderPath
protected
string|null
$composerAutoloaderPath
$isKilled
protected
bool
$isKilled
= false
$classLoaders
private
Threaded|null
$classLoaders
= null
Methods
getClassLoaders()
public
getClassLoaders() : array<string|int, ClassLoader>
Return values
array<string|int, ClassLoader> —getThreadName()
public
getThreadName() : string
Return values
string —quit()
Stops the thread using the best way possible. Try to stop it yourself before calling this.
public
quit() : void
Return values
void —registerClassLoaders()
Registers the class loaders for this thread.
public
registerClassLoaders() : void
WARNING: This method MUST be called from any descendent threads' run() method to make autoloading usable. If you do not do this, you will not be able to use new classes that were not loaded when the thread was started (unless you are using a custom autoloader).
Return values
void —run()
public
final run() : void
Return values
void —setClassLoaders()
public
setClassLoaders([array<string|int, ClassLoader> $autoloaders = null ]) : void
Parameters
- $autoloaders : array<string|int, ClassLoader> = null
Return values
void —start()
public
start([int $options = PTHREADS_INHERIT_NONE ]) : bool
Parameters
- $options : int = PTHREADS_INHERIT_NONE
Return values
bool —onRun()
Runs code on the thread.
protected
abstract onRun() : void