mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-07-07 02:21:46 +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{
|
}else{
|
||||||
$task = new ChunkRequestTask($this, $x, $z);
|
$task = new ChunkRequestTask($this, $x, $z);
|
||||||
$this->server->getScheduler()->scheduleAsyncTask($task);
|
$this->server->getScheduler()->scheduleAsyncTask($task);
|
||||||
$this->chunkSendTasks[$index] = $task;
|
$this->chunkSendTasks[$index] = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -45,6 +45,9 @@ class ServerScheduler{
|
|||||||
|
|
||||||
protected $asyncTasks = 0;
|
protected $asyncTasks = 0;
|
||||||
|
|
||||||
|
/** @var AsyncTask[] */
|
||||||
|
protected $asyncTaskStorage = [];
|
||||||
|
|
||||||
/** @var int */
|
/** @var int */
|
||||||
private $ids = 1;
|
private $ids = 1;
|
||||||
|
|
||||||
@ -75,6 +78,7 @@ class ServerScheduler{
|
|||||||
*/
|
*/
|
||||||
public function scheduleAsyncTask(AsyncTask $task){
|
public function scheduleAsyncTask(AsyncTask $task){
|
||||||
$this->asyncPool->submit($task);
|
$this->asyncPool->submit($task);
|
||||||
|
$this->asyncTaskStorage[spl_object_hash($task)] = $task;
|
||||||
++$this->asyncTasks;
|
++$this->asyncTasks;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -214,16 +218,19 @@ class ServerScheduler{
|
|||||||
}
|
}
|
||||||
|
|
||||||
if($this->asyncTasks > 0){ //Garbage collector
|
if($this->asyncTasks > 0){ //Garbage collector
|
||||||
$this->asyncPool->collect(function (AsyncTask $task){
|
$this->asyncPool->collect([$this, "collectAsyncTask"]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function collectAsyncTask(AsyncTask $task){
|
||||||
if($task->isFinished() and !$task->isCompleted()){
|
if($task->isFinished() and !$task->isCompleted()){
|
||||||
--$this->asyncTasks;
|
--$this->asyncTasks;
|
||||||
$task->onCompletion(Server::getInstance());
|
$task->onCompletion(Server::getInstance());
|
||||||
$task->setCompleted();
|
$task->setCompleted();
|
||||||
|
unset($this->asyncTaskStorage[spl_object_hash($task)]);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private function isReady($currentTicks){
|
private function isReady($currentTicks){
|
||||||
|
Loading…
x
Reference in New Issue
Block a user