Use Collectable class on AsyncTask, removed task collection workaround on ServerScheduler

This commit is contained in:
Shoghi Cervantes 2014-10-10 20:53:28 +02:00
parent 8b585fd9f7
commit 0dba14074a
3 changed files with 3 additions and 13 deletions

View File

@ -28,7 +28,7 @@ use pocketmine\Server;
*
* WARNING: Do not call PocketMine-MP API methods from other Threads!!
*/
abstract class AsyncTask extends \Threaded{
abstract class AsyncTask extends \Collectable{
protected $complete = null;
protected $finished = null;
@ -43,6 +43,7 @@ abstract class AsyncTask extends \Threaded{
$this->onRun();
$this->finished = true;
$this->setGarbage();
}

View File

@ -45,9 +45,6 @@ class ServerScheduler{
protected $asyncTasks = 0;
/** @var AsyncTask[] */
protected $asyncTaskStorage = [];
/** @var int */
private $ids = 1;
@ -80,7 +77,6 @@ class ServerScheduler{
$id = $this->nextId();
$task->setTaskId($id);
$this->asyncPool->submit($task);
$this->asyncTaskStorage[$id] = $task;
++$this->asyncTasks;
}
@ -245,12 +241,6 @@ 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);
}
}
}
}
@ -259,7 +249,6 @@ class ServerScheduler{
--$this->asyncTasks;
$task->onCompletion(Server::getInstance());
$task->setCompleted();
unset($this->asyncTaskStorage[$task->getTaskId()]);
return true;
}

@ -1 +1 @@
Subproject commit e565959cc14235329d428c25e7b1a2d1cf4874c7
Subproject commit 1095acf146aaf8c9dffeea4d04999322fd5627d9