Add a timer.

@param float $time_interval 单位s
@param callback $func
@param mixed $args
@param bool $persistent
@return int/false
347319
public static function add($time_interval, $func, $args = array(), $persistent = true)
    {
        if ($time_interval <= 0) {
            echo new Exception("bad time_interval");
            return false;
        }

        if (!is_callable($func)) {
            echo new Exception("not callable");
            return false;
        }
        if($args === null){
            $args = array();
        }
        $real_func = function () use ($func, $args,$persistent, &$timerid) {
            call_user_func_array($func, $args);
            if($persistent === false){
                unset(self::$_tasks[$timerid]);
            }
        };
        $real_time = $time_interval*1000;
        if ($persistent === true) {
            $timerid = swoole_timer_tick($real_time, $real_func);
        } else {
            $timerid = swoole_timer_after($real_time, $real_func);
        }
        if (!isset(self::$_tasks)) {
            self::$_tasks = array();
        }
        self::$_tasks[$timerid] = array($func, (array)$args, $persistent, $real_time);
        return $timerid;
    }
1169095
protected int createNonPersistentAutomaticTimers(String appName, String moduleName, List<AutomaticTimerBean> timerBeans) {
        final boolean isTraceOn = TraceComponent.isAnyTracingEnabled();
        if (isTraceOn && tc.isEntryEnabled())
            Tr.entry(tc, "createNonPersistentAutomaticTimers: " + moduleName);

        int numCreated = 0;

        for (AutomaticTimerBean timerBean : timerBeans) {
            if (timerBean.getNumNonPersistentTimers() != 0) {
                for (TimerMethodData timerMethod : timerBean.getMethods()) {
                    for (TimerMethodData.AutomaticTimer timer : timerMethod.getAutomaticTimers()) {
                        if (!timer.isPersistent()) {
                            if (isTraceOn && tc.isDebugEnabled())
                                Tr.debug(tc, "creating non-persistent automatic timer " + timer);

                            createNonPersistentAutomaticTimer(timerBean, timer, timerMethod);
                            numCreated++;
                        }
                    }
                }
            }
        }

        if (isTraceOn && tc.isEntryEnabled())
            Tr.exit(tc, "createNonPersistentAutomaticTimers: " + numCreated);
        return numCreated;
    }
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;
        }
    }
629815
function until($func,$args=NULL,$timeout=60) {
		if (!$args)
			$args=array();
		$time=time();
		$limit=max(0,min($timeout,$max=ini_get('max_execution_time')-1));
		$out='';
		$flag=FALSE;
		// Not for the weak of heart
		while (
			// Still alive?
			!connection_aborted() &&
			// Got time left?
			(time()-$time+1<$limit) &&
			// Restart session
			$flag=@session_start() &&
			// CAUTION: Callback will kill host if it never becomes truthy!
			!($out=$this->call($func,$args))) {
			session_commit();
			ob_flush();
			flush();
			// Hush down
			sleep(1);
		}
		if ($flag) {
			session_commit();
			ob_flush();
			flush();
		}
		return $out;
	}
843184
public function add(TimeInterval $interval)
    {
        $date = clone $this->date;
        $int = new DateInterval($interval->intervalSpec());
        $date->add($int);
        return $this->dateTimeToTimePoint($date);
    }
1236974
public void setInterval(ReadableInstant start, ReadableInstant end) {
        if (start == null && end == null) {
            long now = DateTimeUtils.currentTimeMillis();
            setInterval(now, now);
        } else {
            long startMillis = DateTimeUtils.getInstantMillis(start);
            long endMillis = DateTimeUtils.getInstantMillis(end);
            Chronology chrono = DateTimeUtils.getInstantChronology(start);
            super.setInterval(startMillis, endMillis, chrono);
        }
    }
268108
function AddCallback(mesgId, callbackFunction, callbackTimeout) {
    var callbackElement, now;

    now = new Date().getTime();

    callbackElement = {
        id      :   mesgId,
        func    :   callbackFunction,
        timeout :   now + callbackTimeout
    };

    callbackList.push(callbackElement);
}
423446
function(args) {
	let service = args.service;
	let record = args.record;
	if (!service || !record || !record.module || !record.enable) {
		return;
	}

	if (service.master) {
		record.module.masterHandler(service.agent, null, function(err) {
			logger.error('interval push should not have a callback.');
		});
	} else {
		record.module.monitorHandler(service.agent, null, function(err) {
			logger.error('interval push should not have a callback.');
		});
	}
}
943845
public void setPersistentTimestamp(long newTimestamp) throws FatalChronosException,
      ChronosException {
    if (newTimestamp <= persistentTimestamp) {
      throw new FatalChronosException("Fatal error to set a smaller timestamp");
    }

    if (LOG.isDebugEnabled()) {
      LOG.debug("Setting persistent timestamp " + newTimestamp + " in ZooKeeper");
    }

    for (int i = 0; i <= connectRetryTimes; ++i) {
      try {
        ZooKeeperUtil.setData(this, persistentTimestampZnode, ZooKeeperUtil.longToBytes(newTimestamp));
        persistentTimestamp = newTimestamp;
        break;
      } catch (KeeperException e) {
        if (i == connectRetryTimes) {
          throw new ChronosException(
              "Error to set persistent timestamp in ZooKeeper after retrying", e);
        }
        LOG.info("Exception to set persistent timestamp in ZooKeeper, retry " + (i + 1) + " times");
      }
    }
  }
33656
function when (condition, fn, interval) {
  if (condition()) return callback.async(fn);

  var ref = setInterval(function () {
    if (!condition()) return;
    callback(fn);
    clearInterval(ref);
  }, interval || 10);
}
994923
public function cacheCallback($method, $args, Closure $callback, $time = null)
    {
        // Cache disabled, just execute query & return result
        if ($this->skippedCache() === true) {
            return call_user_func($callback);
        }

        // Use the called class name as the tag
        $tag = get_called_class();

        return self::getCacheInstance()->tags(['repositories', $tag])->remember(
            $this->getCacheKey($method, $args, $tag),
            $this->getCacheExpiresTime($time),
            $callback
        );
    }
633824
public function each(\DateInterval $interval, \Closure $callback)
    {
        $period = new static($this->start(), $this->start()->add($interval));

        do {
            $callback(new static(
                $period->start(),
                $period->end() > $this->endDate ? $this->endDate : $period->end()
            ));
        } while ($period->add($interval)->start() < $this->endDate);

        return $this;
    }
662608
def set(self, time_sec, callback_fn, *args, **kwdargs):
        
        timer = self.timer()
        timer.set_callback('expired', callback_fn, *args, **kwdargs)
        timer.set(time_sec)
        return timer
1306728
public function execute(callable $function, array $arguments = [])
    {
        $delayFunction = $this->delayFunction;
        $retryAttempt = 0;

        $continue = true;
        do {
            try {
                $res = call_user_func_array($function, $arguments);
                $continue = false;
                return $res;
            } catch (\Exception $exception) {
                if ($this->retryFunction) {
                    if (!call_user_func($this->retryFunction, $exception)) {
                        throw $exception;
                    }
                }

                if ($retryAttempt < $this->retries) {
                    $delay = $delayFunction($exception);
                    $delay += [
                        'seconds' => 0,
                        'nanos' => 0
                    ];

                    time_nanosleep($delay['seconds'], $delay['nanos']);

                    $retryAttempt++;
                } else {
                    $continue = false;
                    throw $exception;
                }
            }
        } while ($continue);
    }
1238254
def repeat(self, time, function, args = []):
        """"""
        callback_id = self.tk.after(time, self._call_wrapper, time, function, *args)
        self._callback[function] = [callback_id, True]
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); }
    });
  }
790692
function (func, delay) {
    var timer = null;

    return function () {
      var context = this, args = arguments;

      if (timer === null) {
        timer = setTimeout(function () {
          func.apply(context, args);
          timer = null;
        }, delay);
      }
    };
  }