Skip to content

Instantly share code, notes, and snippets.

@Omattyao
Last active December 21, 2015 04:18
Show Gist options
  • Save Omattyao/6248054 to your computer and use it in GitHub Desktop.
Save Omattyao/6248054 to your computer and use it in GitHub Desktop.
<?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