Last active
December 21, 2015 04:18
-
-
Save Omattyao/6248054 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
private $id = (int) 0; | |
private $schedule = array(); | |
public function schedule($ticks, $method, $args, $repeat = false) | |
{ | |
$id = $this->id; | |
$this->schedule[$id] = array($tocks, $method, $args, $repeat); | |
$this->api->schedule($ticks, array($this, "callback", array($method, $args), $repeat, $id); | |
$this->id++; | |
return $id; | |
} | |
public function cancelSchedule($id) | |
{ | |
@unset($this->schedule[$id]); | |
} | |
public function getSchedule($id) | |
{ | |
if (!isset($this->schedule[$id])) return false; | |
return $this->schedule[$id]; | |
} | |
public function callback($args, $id) | |
{ | |
$schedule = $this->getSchedule($id); | |
if ($schedule === false) return false; | |
$method = $args[0]; | |
$params = $args[1]; | |
@call_user_func_array(array($this, $method), $params); | |
if ($schedule[3] === false) { | |
unset($this->schedule[$id]); | |
} | |
} | |
> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment