mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-09-05 17:36:12 +00:00
Improved chunk sending, moved chunk encoding and compression to another thread
This commit is contained in:
@ -29,36 +29,49 @@ use pocketmine\Server;
|
||||
*/
|
||||
abstract class AsyncTask extends \Threaded{
|
||||
|
||||
private $complete;
|
||||
private $finished;
|
||||
private $result;
|
||||
private $complete = null;
|
||||
private $finished = null;
|
||||
private $result = null;
|
||||
|
||||
public function run(){
|
||||
$this->lock();
|
||||
$this->finished = false;
|
||||
$this->complete = false;
|
||||
$this->result = null;
|
||||
$this->unlock();
|
||||
|
||||
$this->onRun();
|
||||
|
||||
$this->lock();
|
||||
$this->finished = true;
|
||||
$this->unlock();
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
public function isFinished(){
|
||||
return $this->synchronized(function(){
|
||||
return $this->finished === true;
|
||||
});
|
||||
|
||||
return $this->finished === true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
public function isCompleted(){
|
||||
return $this->complete === true;
|
||||
}
|
||||
|
||||
public function setCompleted(){
|
||||
$this->complete = true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return mixed
|
||||
*/
|
||||
public function getResult(){
|
||||
return $this->synchronized(function (){
|
||||
$this->finished = true;
|
||||
|
||||
return @unserialize($this->result);
|
||||
});
|
||||
return @unserialize($this->result);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -215,12 +215,12 @@ class ServerScheduler{
|
||||
|
||||
if($this->asyncTasks > 0){ //Garbage collector
|
||||
$this->asyncPool->collect(function (AsyncTask $task){
|
||||
if($task->isFinished()){
|
||||
if($task->isFinished() and !$task->isCompleted()){
|
||||
--$this->asyncTasks;
|
||||
$task->onCompletion(Server::getInstance());
|
||||
$task->setCompleted();
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
});
|
||||
}
|
||||
|
Reference in New Issue
Block a user