Add a periodic timer

@param int      $interval Interval
@param callable $callback Callback
770411
public function addPeriodicTimer(int $interval, callable $callback): void
    {
        $this->loop->addPeriodicTimer($interval, $callback);
    }
320660
public function push(Period $interval, Period ...$intervals): void
    {
        $this->intervals = array_merge($this->intervals, [$interval], $intervals);
    }
927938
private static function resolveDateInterval($interval) : \DateInterval
    {
        if ($interval instanceof DateInterval) {
            return $interval->toInternalDateInterval();
        }
        
        if (is_string($interval)) {
            return new \DateInterval($interval);
        }
        
        if ($interval instanceof \DateInterval) {
            return $interval;
        }
        
        throw new \InvalidArgumentException('Interval must be a string or an instance of DateInterval.');
    }
1273639
function (minimumInterval, callback) {
    var timeout = null;
    return function () {
        var that = this, args = arguments;
        if(timeout === null) {
            timeout = setTimeout(function () {
                timeout = null;
            }, minimumInterval);
            callback.apply(that, args);
        }
    };
}
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);
    }
986194
def fixed_interval_scheduler(interval):
    
    start = time.time()
    next_tick = start

    while True:
        next_tick += interval
        yield next_tick
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;
        }
    }
74099
public function tick(int $interval, Closure $callback, $parameters = null): int
    {
        return $this->getSwoole()->tick($interval, $callback, $parameters);
    }
70876
public function work($interval = ResqueWorkerBase::DEFAULT_INTERVAL, $blocking = false)
    {
        if ($interval !== null) {
            $this->interval = $interval;
        }

        $this->updateProcLine('Starting');
        $this->startup();

        while (true) {
            if (function_exists('pcntl_signal_dispatch')) {
                pcntl_signal_dispatch();
            }
            if ($this->shutdown) {
                break;
            }

            // Attempt to find and reserve a job
            $job = false;
            if (!$this->paused) {
                if ($blocking === true) {
                    $this->logger->log(
                        LogLevel::INFO,
                        'Starting blocking with timeout of {interval}',
                        ['interval' => $this->interval]
                    );
                    $this->updateProcLine(
                        'Waiting for ' . implode(',', $this->queues) . ' with blocking timeout ' . $this->interval
                    );
                } else {
                    $this->updateProcLine(
                        'Waiting for ' . implode(',', $this->queues) . ' with interval ' . $this->interval);
                }

                $job = $this->reserve($blocking, $this->interval);
            }

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

                if ($blocking === false) {
                    // If no job was found, we sleep for $this->interval before continuing and checking again
                    $this->logger->log(LogLevel::INFO, 'Sleeping for {interval}', ['interval' => $this->interval]);
                    if ($this->paused) {
                        $this->updateProcLine('Paused');
                    } else {
                        $this->updateProcLine('Waiting for ' . implode(',', $this->queues));
                    }

                    usleep($this->interval * 1000000);
                }

                continue;
            }

            $this->logger->log(LogLevel::NOTICE, 'Starting work on {job}', ['job' => $job]);
            $this->resqueInstance->events->trigger('beforeFork', $job);
            $this->workingOn($job);

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

            // Forked and we're the child. Run the job.
            if ($this->child === 0 || $this->child === false) {
                $status = 'Processing ' . $job->queue . ' since ' . date('d/m/Y h:i:s a');
                $this->updateProcLine($status);
                $this->logger->log(LogLevel::INFO, $status);
                $this->perform($job);
                if ($this->child === 0) {
                    exit(0);
                }
            }

            if ($this->child > 0) {
                // Parent process, sit and wait
                $status = 'Forked ' . $this->child . ' at ' . date('d/m/Y h:i:s a');
                $this->updateProcLine($status);
                $this->logger->log(LogLevel::INFO, $status);

                // Wait until the child process finishes before continuing
                pcntl_wait($status);
                $exitStatus = pcntl_wexitstatus($status);
                if ($exitStatus !== 0) {
                    $job->fail(new ResqueJobForceExitException(
                        'Job exited with exit code ' . $exitStatus
                    ));
                }
            }

            $this->child = null;
            $this->doneWorking();
        }

        $this->unregisterWorker();
    }
669889
public function iterateDates(\Closure $callback)
    {
        $interval = new \DateInterval('P1D');

        $period = new \DatePeriod($this->start()->copy()->startOfDay(), $interval, $this->end()->copy()->startOfDay());

        foreach ($period as $date) {
            $callback($date);
        }

        return $this;
    }
683285
public function setCallback($callback = false)
    {
        if(!$callback)
        {
            $callback = \Ginger\System\Parameters::$callback;
        }
        $this->callback = $callback;
    }
351017
protected function setupHeartbeat($interval)
    {
        $this->heartbeatInterval = $interval;
        if (isset($this->heartbeatTimer)) {
            $this->heartbeatTimer->cancel();
        }

        $interval             = $interval / 1000;
        $this->heartbeatTimer = $this->loop->addPeriodicTimer($interval, [$this, 'heartbeat']);
        $this->heartbeat();

        $this->logger->info('heartbeat timer initilized', ['interval' => $interval * 1000]);
    }
601647
public void setPeriod(ReadableInterval interval) {
        if (interval == null) {
            setPeriod(0L);
        } else {
            Chronology chrono = DateTimeUtils.getChronology(interval.getChronology());
            setPeriod(interval.getStartMillis(), interval.getEndMillis(), chrono);
        }
    }
890001
def add_periodic_callback(self, callback, period_milliseconds, callback_id=None):
        

        cb = _AsyncPeriodic(callback, period_milliseconds, io_loop=self._loop)
        callback_id = self._assign_remover(callback, callback_id, self._periodic_callback_removers, cb.stop)
        cb.start()
        return callback_id
97989
public function publishPeriodically($interval, Message $message, callable $generator)
    {
        if (!$this->isConnected) {
            return new RejectedPromise(new \LogicException('The client is not connected.'));
        }

        $deferred = new Deferred();

        $this->timer[] = $this->loop->addPeriodicTimer(
            $interval,
            function () use ($message, $generator, $deferred) {
                $this->publish($message->withPayload($generator($message->getTopic())))->then(
                    function ($value) use ($deferred) {
                        $deferred->notify($value);
                    },
                    function (\Exception $e) use ($deferred) {
                        $deferred->reject($e);
                    }
                );
            }
        );

        return $deferred->promise();
    }
1118293
def set_keepalive(self, interval, callback):
        
        self.__keepalive_interval = interval
        self.__keepalive_callback = callback
        self.__keepalive_last = time.time()
692876
function onTimer($timerId)
    {
        $now = time();
        //echo "timer $interval\n";
        foreach ($this->wait_requests as $id => $request)
        {
            if ($request->time < $now - $this->request_timeout)
            {
                $response = new Swoole\Response;
                $response->setHeader('Access-Control-Allow-Origin', $this->origin);
                $response->body = json_encode(array('success' => 0, 'text' => 'timeout'));
                $this->response($request, $response);
                unset($this->wait_requests[$id]);
            }
        }
    }