mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-09-06 17:59:48 +00:00
AsyncWorker: Use statics for thread-local worker storage instead of globals
This commit is contained in:
@ -126,29 +126,29 @@ abstract class AsyncTask extends Collectable{
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets something into the local thread store.
|
||||
* You have to initialize this in some way from the task on run
|
||||
* @see AsyncWorker::getFromThreadStore()
|
||||
*
|
||||
* @param string $identifier
|
||||
* @return mixed
|
||||
*/
|
||||
public function getFromThreadStore(string $identifier){
|
||||
global $store;
|
||||
return ($this->isGarbage() or !isset($store[$identifier])) ? null : $store[$identifier];
|
||||
if($this->worker === null or $this->isGarbage()){
|
||||
throw new \BadMethodCallException("Objects stored in AsyncWorker thread-local storage can only be retrieved during task execution");
|
||||
}
|
||||
return $this->worker->getFromThreadStore($identifier);
|
||||
}
|
||||
|
||||
/**
|
||||
* Saves something into the local thread store.
|
||||
* This might get deleted at any moment.
|
||||
* @see AsyncWorker::saveToThreadStore()
|
||||
*
|
||||
* @param string $identifier
|
||||
* @param mixed $value
|
||||
*/
|
||||
public function saveToThreadStore(string $identifier, $value){
|
||||
global $store;
|
||||
if(!$this->isGarbage()){
|
||||
$store[$identifier] = $value;
|
||||
if($this->worker === null or $this->isGarbage()){
|
||||
throw new \BadMethodCallException("Objects can only be added to AsyncWorker thread-local storage during task execution");
|
||||
}
|
||||
$this->worker->saveToThreadStore($identifier, $value);
|
||||
}
|
||||
|
||||
/**
|
||||
|
Reference in New Issue
Block a user