mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-04-22 08:44:01 +00:00
Revert "Use Collectable class on AsyncTask, removed task collection workaround on ServerScheduler"
This reverts commit 0dba14074a634e82539735c3be88c6ae31b0be05.
This commit is contained in:
parent
645c00b2f7
commit
baf06dc363
@ -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();
|
||||
|
||||
}
|
||||
|
||||
|
@ -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;
|
||||
}
|
||||
|
2
src/spl
2
src/spl
@ -1 +1 @@
|
||||
Subproject commit 1095acf146aaf8c9dffeea4d04999322fd5627d9
|
||||
Subproject commit e565959cc14235329d428c25e7b1a2d1cf4874c7
|
Loading…
x
Reference in New Issue
Block a user