Fixed #1501 executing AsyncTasks blocks other threads

This commit is contained in:
Shoghi Cervantes
2014-06-22 12:50:24 +02:00
parent e381313747
commit 7f795bc041
5 changed files with 42 additions and 110 deletions

View File

@ -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
*