Use Console Thread for Async I/O

This commit is contained in:
Shoghi Cervantes Pueyo
2012-12-29 19:10:04 +01:00
parent b3cc13d4f2
commit 302c865f4e
6 changed files with 56 additions and 64 deletions

View File

@ -29,7 +29,7 @@ class Async extends Thread {
/**
* Provide a passthrough to call_user_func_array
**/
public function __construct($method, $params){
public function __construct($method, $params = array()){
$this->method = $method;
$this->params = $params;
$this->result = null;
@ -40,15 +40,17 @@ class Async extends Thread {
* The smallest thread in the world
**/
public function run(){
if (($this->result=call_user_func_array($this->method, $this->params))) {
if(($this->result=call_user_func_array($this->method, $this->params))){
return true;
} else return false;
}else{
return false;
}
}
/**
* Static method to create your threads from functions ...
**/
public static function call($method, $params){
public static function call($method, $params = array()){
$thread = new Async($method, $params);
if($thread->start()){
return $thread;