mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-09-06 17:59:48 +00:00
Fixed #1501 executing AsyncTasks blocks other threads
This commit is contained in:
@ -33,19 +33,30 @@ abstract class AsyncTask extends \Threaded{
|
||||
private $result;
|
||||
|
||||
public function run(){
|
||||
$this->lock();
|
||||
$this->finished = false;
|
||||
$this->complete = false;
|
||||
$this->result = null;
|
||||
$this->onRun();
|
||||
$this->finished = true;
|
||||
$this->complete = $this->result === null ? true : false;
|
||||
$this->unlock();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
public function isCompleted(){
|
||||
return $this->complete === true;
|
||||
return $this->synchronized(function(){
|
||||
return $this->complete === true;
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
public function isFinished(){
|
||||
return $this->synchronized(function(){
|
||||
return $this->finished === true;
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
@ -73,13 +84,6 @@ abstract class AsyncTask extends \Threaded{
|
||||
$this->result = @serialize($result);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
public function isFinished(){
|
||||
return $this->finished === true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Actions to execute when run
|
||||
*
|
||||
|
Reference in New Issue
Block a user