XPSPL\Routine::add_idle PHP Method

add_idle() public method

Adds a new function to idle the engine.
public add_idle ( SIG_Routine $routine ) : void
$routine SIG_Routine
return void
    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;
            });
        }
    }

Usage Example

コード例 #1
0
ファイル: sig_awake.php プロジェクト: prggmr/xpspl
 /**
  * Runs the routine.
  *
  * This checks if the appriorate amount of time has passed and emits the 
  * awake signal if so.
  * 
  * @return  boolean
  */
 public function routine(\XPSPL\Routine $routine = null)
 {
     if ($this->get_idle()->has_time_passed()) {
         $routine->add_signal($this);
         $this->get_idle()->set_time($this->_time);
     }
     $routine->add_idle($this);
     return true;
 }
All Usage Examples Of XPSPL\Routine::add_idle