mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-04-19 23:44:17 +00:00
Apply typehints to all AsyncTask methods
Since we're breaking API here anyway, no point in holding back on this.
This commit is contained in:
parent
d62e00cc74
commit
37190c9a65
@ -126,7 +126,7 @@ class TimingsCommand extends VanillaCommand{
|
||||
$this->storeLocal($sender);
|
||||
}
|
||||
|
||||
public function onCompletion(){
|
||||
public function onCompletion() : void{
|
||||
$sender = $this->fetchLocal();
|
||||
if($sender instanceof Player and !$sender->isOnline()){ // TODO replace with a more generic API method for checking availability of CommandSender
|
||||
return;
|
||||
|
@ -36,7 +36,7 @@ class LightPopulationTask extends AsyncTask{
|
||||
$this->chunk = $chunk->fastSerialize();
|
||||
}
|
||||
|
||||
public function onRun(){
|
||||
public function onRun() : void{
|
||||
/** @var Chunk $chunk */
|
||||
$chunk = Chunk::fastDeserialize($this->chunk);
|
||||
|
||||
|
@ -63,7 +63,7 @@ abstract class AsyncTask extends Collectable{
|
||||
|
||||
private $crashed = false;
|
||||
|
||||
public function run(){
|
||||
public function run() : void{
|
||||
$this->result = null;
|
||||
|
||||
if(!$this->cancelRun){
|
||||
@ -89,7 +89,7 @@ abstract class AsyncTask extends Collectable{
|
||||
return $this->serialized ? unserialize($this->result) : $this->result;
|
||||
}
|
||||
|
||||
public function cancelRun(){
|
||||
public function cancelRun() : void{
|
||||
$this->cancelRun = true;
|
||||
}
|
||||
|
||||
@ -108,19 +108,19 @@ abstract class AsyncTask extends Collectable{
|
||||
* @param mixed $result
|
||||
* @param bool $serialize
|
||||
*/
|
||||
public function setResult($result, bool $serialize = true){
|
||||
public function setResult($result, bool $serialize = true) : void{
|
||||
$this->result = $serialize ? serialize($result) : $result;
|
||||
$this->serialized = $serialize;
|
||||
}
|
||||
|
||||
public function setTaskId(int $taskId){
|
||||
public function setTaskId(int $taskId) : void{
|
||||
$this->taskId = $taskId;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int|null
|
||||
*/
|
||||
public function getTaskId(){
|
||||
public function getTaskId() : ?int{
|
||||
return $this->taskId;
|
||||
}
|
||||
|
||||
@ -143,7 +143,7 @@ abstract class AsyncTask extends Collectable{
|
||||
* @param string $identifier
|
||||
* @param mixed $value
|
||||
*/
|
||||
public function saveToThreadStore(string $identifier, $value){
|
||||
public function saveToThreadStore(string $identifier, $value) : void{
|
||||
if($this->worker === null or $this->isGarbage()){
|
||||
throw new \BadMethodCallException("Objects can only be added to AsyncWorker thread-local storage during task execution");
|
||||
}
|
||||
@ -164,18 +164,14 @@ abstract class AsyncTask extends Collectable{
|
||||
|
||||
/**
|
||||
* Actions to execute when run
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
abstract public function onRun();
|
||||
abstract public function onRun() : void;
|
||||
|
||||
/**
|
||||
* Actions to execute when completed (on main thread)
|
||||
* Implement this if you want to handle the data in your AsyncTask after it has been processed
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function onCompletion(){
|
||||
public function onCompletion() : void{
|
||||
|
||||
}
|
||||
|
||||
@ -192,7 +188,7 @@ abstract class AsyncTask extends Collectable{
|
||||
/**
|
||||
* @internal Only call from AsyncPool.php on the main thread
|
||||
*/
|
||||
public function checkProgressUpdates(){
|
||||
public function checkProgressUpdates() : void{
|
||||
while($this->progressUpdates->count() !== 0){
|
||||
$progress = $this->progressUpdates->shift();
|
||||
$this->onProgressUpdate(unserialize($progress));
|
||||
@ -207,7 +203,7 @@ abstract class AsyncTask extends Collectable{
|
||||
* @param mixed $progress The parameter passed to {@link AsyncTask#publishProgress}. It is serialize()'ed
|
||||
* and then unserialize()'ed, as if it has been cloned.
|
||||
*/
|
||||
public function onProgressUpdate($progress){
|
||||
public function onProgressUpdate($progress) : void{
|
||||
|
||||
}
|
||||
|
||||
@ -232,9 +228,8 @@ abstract class AsyncTask extends Collectable{
|
||||
*
|
||||
* @param mixed $complexData the data to store
|
||||
*
|
||||
* @throws \BadMethodCallException if called from any thread except the main thread
|
||||
*/
|
||||
protected function storeLocal($complexData){
|
||||
protected function storeLocal($complexData) : void{
|
||||
if($this->worker !== null and $this->worker === \Thread::getCurrentThread()){
|
||||
throw new \BadMethodCallException("Objects can only be stored from the parent thread");
|
||||
}
|
||||
|
@ -49,7 +49,7 @@ class BulkCurlTask extends AsyncTask{
|
||||
$this->operations = serialize($operations);
|
||||
}
|
||||
|
||||
public function onRun(){
|
||||
public function onRun() : void{
|
||||
$operations = unserialize($this->operations);
|
||||
$results = [];
|
||||
foreach($operations as $op){
|
||||
|
@ -47,7 +47,7 @@ class DumpWorkerMemoryTask extends AsyncTask{
|
||||
$this->maxStringSize = $maxStringSize;
|
||||
}
|
||||
|
||||
public function onRun(){
|
||||
public function onRun() : void{
|
||||
MemoryManager::dumpMemory(
|
||||
$this->worker,
|
||||
$this->outputFolder . DIRECTORY_SEPARATOR . "AsyncWorker#" . $this->worker->getAsyncWorkerId(),
|
||||
|
@ -43,7 +43,7 @@ class FileWriteTask extends AsyncTask{
|
||||
$this->flags = $flags;
|
||||
}
|
||||
|
||||
public function onRun(){
|
||||
public function onRun() : void{
|
||||
try{
|
||||
file_put_contents($this->path, $this->contents, $this->flags);
|
||||
}catch(\Throwable $e){
|
||||
|
@ -25,7 +25,7 @@ namespace pocketmine\scheduler;
|
||||
|
||||
class GarbageCollectionTask extends AsyncTask{
|
||||
|
||||
public function onRun(){
|
||||
public function onRun() : void{
|
||||
gc_enable();
|
||||
gc_collect_cycles();
|
||||
}
|
||||
|
@ -146,7 +146,7 @@ class SendUsageTask extends AsyncTask{
|
||||
$this->data = json_encode($data/*, JSON_PRETTY_PRINT*/);
|
||||
}
|
||||
|
||||
public function onRun(){
|
||||
public function onRun() : void{
|
||||
try{
|
||||
Internet::postURL($this->endpoint, $this->data, 5, [
|
||||
"Content-Type: application/json",
|
||||
|
@ -42,7 +42,7 @@ class UpdateCheckTask extends AsyncTask{
|
||||
$this->channel = $channel;
|
||||
}
|
||||
|
||||
public function onRun(){
|
||||
public function onRun() : void{
|
||||
$error = "";
|
||||
$response = Internet::getURL($this->endpoint . "?channel=" . $this->channel, 4, [], $error);
|
||||
$this->error = $error;
|
||||
@ -70,7 +70,7 @@ class UpdateCheckTask extends AsyncTask{
|
||||
}
|
||||
}
|
||||
|
||||
public function onCompletion(){
|
||||
public function onCompletion() : void{
|
||||
/** @var AutoUpdater $updater */
|
||||
$updater = $this->fetchLocal();
|
||||
if($this->hasResult()){
|
||||
|
@ -39,7 +39,7 @@ class AsyncTaskMainLoggerTest extends Test{
|
||||
$this->storeLocal($testObject);
|
||||
}
|
||||
|
||||
public function onRun(){
|
||||
public function onRun() : void{
|
||||
ob_start();
|
||||
MainLogger::getLogger()->info("Testing");
|
||||
if(strpos(ob_get_contents(), "Testing") !== false){
|
||||
@ -48,7 +48,7 @@ class AsyncTaskMainLoggerTest extends Test{
|
||||
ob_end_flush();
|
||||
}
|
||||
|
||||
public function onCompletion(){
|
||||
public function onCompletion() : void{
|
||||
/** @var AsyncTaskMainLoggerTest $test */
|
||||
$test = $this->fetchLocal();
|
||||
$test->setResult($this->success ? Test::RESULT_OK : Test::RESULT_FAILED);
|
||||
|
@ -50,7 +50,7 @@ class AsyncTaskMemoryLeakTest extends Test{
|
||||
class TestAsyncTask extends AsyncTask{
|
||||
public static $destroyed = false;
|
||||
|
||||
public function onRun(){
|
||||
public function onRun() : void{
|
||||
usleep(50 * 1000); //1 server tick
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user