diff --git a/src/pocketmine/scheduler/AsyncTask.php b/src/pocketmine/scheduler/AsyncTask.php index ffa7fc8ec..c1adfa1db 100644 --- a/src/pocketmine/scheduler/AsyncTask.php +++ b/src/pocketmine/scheduler/AsyncTask.php @@ -28,7 +28,7 @@ use pocketmine\Server; * * WARNING: Do not call PocketMine-MP API methods from other Threads!! */ -abstract class AsyncTask extends \Collectable{ +abstract class AsyncTask extends \Threaded{ protected $complete = null; protected $finished = null; @@ -43,7 +43,6 @@ abstract class AsyncTask extends \Collectable{ $this->onRun(); $this->finished = true; - $this->setGarbage(); } diff --git a/src/pocketmine/scheduler/ServerScheduler.php b/src/pocketmine/scheduler/ServerScheduler.php index e832b8b74..696ac2a7e 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; @@ -77,6 +80,7 @@ class ServerScheduler{ $id = $this->nextId(); $task->setTaskId($id); $this->asyncPool->submit($task); + $this->asyncTaskStorage[$id] = $task; ++$this->asyncTasks; } @@ -241,6 +245,12 @@ class ServerScheduler{ if($this->asyncTasks > 0){ //Garbage collector $this->asyncPool->collect([$this, "collectAsyncTask"]); + + foreach($this->asyncTaskStorage as $asyncTask){ + if($asyncTask->isFinished() and !$asyncTask->isCompleted()){ + $this->collectAsyncTask($asyncTask); + } + } } } @@ -249,6 +259,7 @@ class ServerScheduler{ --$this->asyncTasks; $task->onCompletion(Server::getInstance()); $task->setCompleted(); + unset($this->asyncTaskStorage[$task->getTaskId()]); return true; } diff --git a/src/spl b/src/spl index 1095acf14..e565959cc 160000 --- a/src/spl +++ b/src/spl @@ -1 +1 @@ -Subproject commit 1095acf146aaf8c9dffeea4d04999322fd5627d9 +Subproject commit e565959cc14235329d428c25e7b1a2d1cf4874c7