mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-04-21 16:24:05 +00:00
Fixed worker pool AsyncTask storage
This commit is contained in:
parent
22552cdd72
commit
637d9da5a6
@ -1349,7 +1349,7 @@ class Level implements ChunkManager, Metadatable{
|
||||
}else{
|
||||
$task = new ChunkRequestTask($this, $x, $z);
|
||||
$this->server->getScheduler()->scheduleAsyncTask($task);
|
||||
$this->chunkSendTasks[$index] = $task;
|
||||
$this->chunkSendTasks[$index] = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -45,6 +45,9 @@ class ServerScheduler{
|
||||
|
||||
protected $asyncTasks = 0;
|
||||
|
||||
/** @var AsyncTask[] */
|
||||
protected $asyncTaskStorage = [];
|
||||
|
||||
/** @var int */
|
||||
private $ids = 1;
|
||||
|
||||
@ -75,6 +78,7 @@ class ServerScheduler{
|
||||
*/
|
||||
public function scheduleAsyncTask(AsyncTask $task){
|
||||
$this->asyncPool->submit($task);
|
||||
$this->asyncTaskStorage[spl_object_hash($task)] = $task;
|
||||
++$this->asyncTasks;
|
||||
}
|
||||
|
||||
@ -214,18 +218,21 @@ class ServerScheduler{
|
||||
}
|
||||
|
||||
if($this->asyncTasks > 0){ //Garbage collector
|
||||
$this->asyncPool->collect(function (AsyncTask $task){
|
||||
if($task->isFinished() and !$task->isCompleted()){
|
||||
--$this->asyncTasks;
|
||||
$task->onCompletion(Server::getInstance());
|
||||
$task->setCompleted();
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
});
|
||||
$this->asyncPool->collect([$this, "collectAsyncTask"]);
|
||||
}
|
||||
}
|
||||
|
||||
public function collectAsyncTask(AsyncTask $task){
|
||||
if($task->isFinished() and !$task->isCompleted()){
|
||||
--$this->asyncTasks;
|
||||
$task->onCompletion(Server::getInstance());
|
||||
$task->setCompleted();
|
||||
unset($this->asyncTaskStorage[spl_object_hash($task)]);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private function isReady($currentTicks){
|
||||
return count($this->tasks) > 0 and $this->queue->current()->getNextRun() <= $currentTicks;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user