mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-08-20 10:00:31 +00:00
Use Collectable class on AsyncTask, removed task collection workaround on ServerScheduler
This commit is contained in:
parent
8b585fd9f7
commit
0dba14074a
@ -28,7 +28,7 @@ use pocketmine\Server;
|
|||||||
*
|
*
|
||||||
* WARNING: Do not call PocketMine-MP API methods from other Threads!!
|
* 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 $complete = null;
|
||||||
protected $finished = null;
|
protected $finished = null;
|
||||||
@ -43,6 +43,7 @@ abstract class AsyncTask extends \Threaded{
|
|||||||
$this->onRun();
|
$this->onRun();
|
||||||
|
|
||||||
$this->finished = true;
|
$this->finished = true;
|
||||||
|
$this->setGarbage();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -45,9 +45,6 @@ class ServerScheduler{
|
|||||||
|
|
||||||
protected $asyncTasks = 0;
|
protected $asyncTasks = 0;
|
||||||
|
|
||||||
/** @var AsyncTask[] */
|
|
||||||
protected $asyncTaskStorage = [];
|
|
||||||
|
|
||||||
/** @var int */
|
/** @var int */
|
||||||
private $ids = 1;
|
private $ids = 1;
|
||||||
|
|
||||||
@ -80,7 +77,6 @@ class ServerScheduler{
|
|||||||
$id = $this->nextId();
|
$id = $this->nextId();
|
||||||
$task->setTaskId($id);
|
$task->setTaskId($id);
|
||||||
$this->asyncPool->submit($task);
|
$this->asyncPool->submit($task);
|
||||||
$this->asyncTaskStorage[$id] = $task;
|
|
||||||
++$this->asyncTasks;
|
++$this->asyncTasks;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -245,12 +241,6 @@ class ServerScheduler{
|
|||||||
|
|
||||||
if($this->asyncTasks > 0){ //Garbage collector
|
if($this->asyncTasks > 0){ //Garbage collector
|
||||||
$this->asyncPool->collect([$this, "collectAsyncTask"]);
|
$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;
|
--$this->asyncTasks;
|
||||||
$task->onCompletion(Server::getInstance());
|
$task->onCompletion(Server::getInstance());
|
||||||
$task->setCompleted();
|
$task->setCompleted();
|
||||||
unset($this->asyncTaskStorage[$task->getTaskId()]);
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
2
src/spl
2
src/spl
@ -1 +1 @@
|
|||||||
Subproject commit e565959cc14235329d428c25e7b1a2d1cf4874c7
|
Subproject commit 1095acf146aaf8c9dffeea4d04999322fd5627d9
|
Loading…
x
Reference in New Issue
Block a user