Documentation

AsyncWorker extends Worker
in package

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.

Table of Contents

$composerAutoloaderPath  : string|null
$isKilled  : bool
$classLoaders  : Threaded|null
$id  : int
$logger  : ThreadedLogger
$memoryLimit  : int
$notifier  : SleeperNotifier
$store  : array<string|int, mixed>
__construct()  : mixed
getAsyncWorkerId()  : int
getClassLoaders()  : array<string|int, ClassLoader>
getFromThreadStore()  : mixed
Retrieves mixed data from the worker's thread-local object store.
getLogger()  : ThreadedLogger
getNotifier()  : SleeperNotifier
getThreadName()  : string
handleException()  : void
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.
removeFromThreadStore()  : void
Removes previously-stored mixed data from the worker's thread-local object store.
run()  : void
saveToThreadStore()  : void
Saves mixed data into the worker's thread-local object store. This can be used to store objects which you want to use on this worker thread from multiple AsyncTasks.
setClassLoaders()  : void
start()  : bool
onRun()  : void

Properties

$store

private static array<string|int, mixed> $store = []

Methods

getAsyncWorkerId()

public getAsyncWorkerId() : int
Return values
int

getFromThreadStore()

Retrieves mixed data from the worker's thread-local object store.

public getFromThreadStore(string $identifier) : mixed

Note that the thread-local object store could be cleared and your data might not exist, so your code should account for the possibility that what you're trying to retrieve might not exist.

Objects stored in this storage may ONLY be retrieved while the task is running.

Parameters
$identifier : string
Return values
mixed

getThreadName()

public getThreadName() : string
Return values
string

handleException()

public handleException(Throwable $e) : void
Parameters
$e : Throwable
Return values
void

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

removeFromThreadStore()

Removes previously-stored mixed data from the worker's thread-local object store.

public removeFromThreadStore(string $identifier) : void
Parameters
$identifier : string
Return values
void

saveToThreadStore()

Saves mixed data into the worker's thread-local object store. This can be used to store objects which you want to use on this worker thread from multiple AsyncTasks.

public saveToThreadStore(string $identifier, mixed $value) : void
Parameters
$identifier : string
$value : mixed
Return values
void

start()

public start([int $options = PTHREADS_INHERIT_NONE ]) : bool
Parameters
$options : int = PTHREADS_INHERIT_NONE
Return values
bool

onRun()

protected onRun() : void
Return values
void

Search results