Alias of startWatch.

@param int      $interval
@param int      $timeout
@param \Closure $callback

@return void
189922
public function start($interval = 1000000, $timeout = null, Closure $callback = null)
    {
        $this->startWatch($interval, $timeout, $callback);
    }
620951
public function work($interval = 5)
    {
        $this->updateProcLine('Starting');
        $this->startup();

        while (true) {
            if ($this->shutdown) {
                $this->unregister();
                return;
            }

            // Attempt to find and reserve a job
            $job = false;
            if (!$this->paused) {
                $job = $this->reserve();
            }

            if (!$job) {
                // For an interval of 0, continue now - helps with unit testing etc
                if ($interval == 0) {
                    break;
                }

                // If no job was found, we sleep for $interval before continuing and checking again
                if ($this->paused) {
                    $this->updateProcLine('Paused');
                } else {
                    $this->updateProcLine('Waiting for ' . implode(',', $this->queues));
                }

                usleep($interval * 1000000);
                continue;
            }

            $this->logger->info('got {job}', array('job' => $job));
            $this->workingOn($job);

            $this->child = null;
            $this->child = $this->fork();

            // Forked and we're the child. Run the job.
            if (!$this->child) {
                $status = 'Processing ' . $job->getQueue() . ' since ' . strftime('%F %T');
                $this->updateProcLine($status);
                $this->logger->notice($status);
                $this->perform($job);

                exit(0);
            } elseif ($this->child > 0) {
                // Parent process, sit and wait
                $status = 'Forked ' . $this->child . ' at ' . strftime('%F %T');
                $this->updateProcLine($status);
                $this->logger->info($status);

                // Wait until the child process finishes before continuing
                pcntl_wait($status);
                $exitStatus = pcntl_wexitstatus($status);

                if ($exitStatus !== 0) {
                    $this->failJob($job, new DirtyExitException(
                        'Job exited with exit code ' . $exitStatus
                    ));
                } else {
                    $this->logger->debug('Job returned status code {code}', array('code' => $exitStatus));
                }
            }

            $this->doneWorking();
        }
    }
731317
public function createWatch($endpoint, $params = [], \Closure $callback)
    {
        $watch = new Watch($this, $endpoint, $params, $callback);

        return $watch;
    }
29621
public void setInterval(ReadableInterval interval) {
        if (interval == null) {
            throw new IllegalArgumentException("Interval must not be null");
        }
        long startMillis = interval.getStartMillis();
        long endMillis = interval.getEndMillis();
        Chronology chrono = interval.getChronology();
        super.setInterval(startMillis, endMillis, chrono);
    }
1051648
public static function run($callable, $timeout = 0)
    {
        if (!is_callable($callable)) {
            throw new InvalidArgumentException();
        }

        $timeout = (integer) $timeout;

        if (!function_exists('pcntl_signal')) {
            throw new Exception("PCNTL threading is not supported by your system.");
        }

        pcntl_signal(SIGALRM, function ($signal) use ($timeout) {
            throw new TimeoutException("Timeout reached, execution aborted after {$timeout} second(s).");
        }, true);

        pcntl_alarm($timeout);

        $result = null;

        try {
            $result = $callable();
            pcntl_alarm(0);
        } catch (Throwable $e) {
            pcntl_alarm(0);
            throw $e;
        } catch (Exception $e) {
            pcntl_alarm(0);
            throw $e;
        }

        return $result;
    }
549926
function(interval, callback) {
    if (lookupIntervalId) {
      return;
    }

    isRunning = true;

    if (!callback && _.isFunction(interval)) {
      callback = interval;
      interval = null;
    }

    interval = interval || 500;

    globalSerialDeviceLoader.trigger(function(err) {
      var triggering = false;
      lookupIntervalId = setInterval(function() {
        if (triggering) return;
        triggering = true;
        globalSerialDeviceLoader.trigger(function() {
          triggering = false;
        });
      }, interval);

      if (err && !err.name) {
        err = new Error(err);
      }
      if (callback) { callback(err); }
    });
  }
678133
public function setInterval( $start, $end )
	{
		if( $start * $end > 0 )
			throw new InvalidArgumentException( 'Interval needs to start below 0.' );
		$this->interval	= new Alg_Math_CompactInterval( $start, $end );
	}
617917
function Timer (callback, start) {
  this.callback = callback;
  this.startDate = null;
  if (!exists(start) || start !== false) {
    this.start();
  }
}
827146
public function iterate($timeout)
    {

        // call parent method and sleep for the default timeout
        parent::iterate($timeout);

        // iterate over the timer tasks that has to be executed
        foreach ($this->tasksToExecute as $taskId => $timerTaskWrapper) {
            // this should never happen
            if (!$timerTaskWrapper instanceof \stdClass) {
                // log an error message because we task wrapper has wrong type
                \error(sprintf('Timer-Task-Wrapper %s has wrong type %s', $taskId, get_class($timerTaskWrapper)));
                // we didn't foud a timer task ignore this
                continue;
            }

            // query if the task has to be executed now
            if ($timerTaskWrapper->executeAt < microtime(true)) {
                // load the timer task wrapper we want to execute
                if ($pk = $this->scheduledTimers[$timerId = $timerTaskWrapper->timerId]) {
                    // load the timer service registry
                    $timerServiceRegistry = $this->getApplication()->search(TimerServiceContextInterface::IDENTIFIER);

                    // lookup the timer from the timer service
                    $timer = $timerServiceRegistry->lookup($pk)->getTimers()->get($timerId);

                    // create and execute the timer task
                    $this->timerTasks[$taskId] = $timer->getTimerTask($this->getApplication());

                    // remove the key from the list of tasks to be executed
                    unset($this->tasksToExecute[$taskId]);

                } else {
                    // log an error message because we can't find the timer instance
                    \error(sprintf('Can\'t find timer %s to create timer task %s', $timerTaskWrapper->timerId, $taskId));
                }
            }
        }

        // collect the garbage (finished timer task jobs)
        $this->collectGarbage();

        // profile the size of the timer tasks to be executed
        if ($this->profileLogger) {
            $this->profileLogger->debug(
                sprintf('Processed timer service executor, executing %d timer tasks', sizeof($this->tasksToExecute))
            );
        }
    }
221454
public function watch($command, $interval = 500)
    {
        $count = 0;
        $activeTime = time();
        $maxTime = (int)$this->config['max_watch_time'];
        $intervalUs = $interval * 1000;

        //echo "watch command: $command, refresh interval: {$interval}ms\n";

        while (true) {
            $count++;
            $result = $this->command($command);

            if (0 === strpos($result, 'ERR')) {
                echo "$result\n";
                echo "error command: $command. ";
                break;
            }

            // clear screen before output
            echo "\033[2JThe {$count} times watch {$command} result(refresh interval: {$interval}ms):\n{$result}\n";

            if ($maxTime > 0 && time() - $activeTime >= $maxTime) {
                echo 'watch time end. ';
                break;
            }

            usleep($intervalUs);
        }

        echo "Quit\n";
    }
805692
public static Timer setInterval(int milliseconds, TimerCallback callback) {
		IntervalTimer interval = new IntervalTimer();
		interval.setId(nativeSetInterval(milliseconds, callback, interval));
		return interval;
	}
669798
public function runCallback( \Closure $callback, $postReinitialize = true )
    {
        $this->requestInit();

        try
        {
            $return = $callback();
        }
        catch ( Exception $e )
        {
            $this->shutdown( $postReinitialize );
            throw $e;
        }

        $this->shutdown( $postReinitialize );

        return $return;
    }
300671
public function block($timeout, $callback = null)
    {
        $starting = time();

        while (! $this->acquire()) {
            if (time() - $timeout >= $starting) {
                throw new LimiterTimeoutException;
            }

            usleep(750 * 1000);
        }

        if (is_callable($callback)) {
            $callback();
        }

        return true;
    }
1018802
public function setTimeout(callable $cb, float $timeout)
    {
        $triggerTime = microtime(true) + ($timeout);

        if (!$this->timers) {
            // Special case when the timers array was empty.
            $this->timers[] = [$triggerTime, $cb];

            return;
        }

        // We need to insert these values in the timers array, but the timers
        // array must be in reverse-order of trigger times.
        //
        // So here we search the array for the insertion point.
        $index = count($this->timers) - 1;
        while (true) {
            if ($triggerTime < $this->timers[$index][0]) {
                array_splice(
                    $this->timers,
                    $index + 1,
                    0,
                    [[$triggerTime, $cb]]
                );
                break;
            } elseif (0 === $index) {
                array_unshift($this->timers, [$triggerTime, $cb]);
                break;
            }
            --$index;
        }
    }
137696
public static function setTimeout($timeout = 60) {
        if (!is_int($timeout) || $timeout < 0) {
            return false;
        }

        self::$timeout = $timeout;
        return true;
    }
208499
public function iterate($timeout)
    {

        // call parent method and sleep for the default timeout
        parent::iterate($timeout);

        // create the instance and stack it
        $this->synchronized(function ($self) {

            // create the instance only if we're NOT dispatched and a class name is available
            if ($self->dispatched === false && $self->className) {
                // create the instance
                $instance = $self->getApplication()->search(ProviderInterface::IDENTIFIER)->get($self->className);

                // stack the instance
                $self->instances[] = $instance;

                // we're dispatched now
                $self->dispatched = true;
            }

        }, $this);
    }
926707
public static function spin($callable, $timeout = 0, $delay = 100000)
    {
        if (!is_callable($callable)) {
            throw new InvalidArgumentException();
        }

        $closure = function () use ($callable, $timeout, $delay) {
            $timeout = (float) $timeout;
            $start = microtime(true);

            do {
                if ($result = $callable()) {
                    return $result;
                }
                usleep($delay);
                $current = microtime(true);
            } while ($current - $start < $timeout);

            throw new TimeoutException("Timeout reached, execution aborted after {$timeout} second(s).");
        };

        if (!function_exists('pcntl_signal')) {
            return $closure();
        }
        return static::run($closure, $timeout);
    }