diff --git a/src/pocketmine/level/Level.php b/src/pocketmine/level/Level.php index 1ce4ad3fd..15a3e9eb6 100644 --- a/src/pocketmine/level/Level.php +++ b/src/pocketmine/level/Level.php @@ -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; } } } diff --git a/src/pocketmine/scheduler/ServerScheduler.php b/src/pocketmine/scheduler/ServerScheduler.php index bf6ff4e4d..3f07099a7 100644 --- a/src/pocketmine/scheduler/ServerScheduler.php +++ b/src/pocketmine/scheduler/ServerScheduler.php @@ -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; }