public function add_idle(SIG_Routine $routine)
{
if (!$this->_is_stale) {
$this->_is_stale = false;
}
if (count($this->_idle) === 0) {
$this->_idle[] = $routine;
return;
}
foreach ($this->_idle as $_k => $_func) {
if (get_class($_func->get_idle()) === get_class($routine->get_idle())) {
if (!$_func->get_idle()->allow_override()) {
throw new \RuntimeException(sprintf("Idle class %s does not allow override", get_class($_func)));
}
if ($_func->get_idle()->override($routine->get_idle())) {
$this->_idle[$_k] = $routine;
}
// return;
}
}
$this->_idle[] = $routine;
if (count($this->_idle) >= 2) {
usort($this->_idle, function ($a, $b) {
$a = $a->get_idle()->get_priority();
$b = $b->get_idle()->get_priority();
if ($a == $b) {
return 0;
}
return $a < $b ? -1 : 1;
});
}
}