Added AsyncTask::onCompletion()

This commit is contained in:
Shoghi Cervantes
2014-06-25 13:01:39 +02:00
parent f9d9d2b0e5
commit 80aebf2932
4 changed files with 19 additions and 8 deletions

View File

@ -20,6 +20,7 @@
*/
namespace pocketmine\scheduler;
use pocketmine\Server;
/**
* Class used to run async tasks in other threads.
@ -91,4 +92,13 @@ abstract class AsyncTask extends \Threaded{
*/
public abstract function onRun();
/**
* Actions to execute when completed (on main thread)
*
* @param Server $server
*
* @return void
*/
public abstract function onCompletion(Server $server);
}

View File

@ -25,6 +25,7 @@
namespace pocketmine\scheduler;
use pocketmine\plugin\Plugin;
use pocketmine\Server;
use pocketmine\utils\ReversePriorityQueue;
class ServerScheduler{
@ -216,7 +217,7 @@ class ServerScheduler{
$this->asyncPool->collect(function (AsyncTask $task){
if($task->isCompleted() or ($task->isFinished() and !$task->hasResult())){
--$this->asyncTasks;
$task->onCompletion(Server::getInstance());
return true;
}