Interval.js

@constructor
@param {function} func - The function you want to be called repeatly
@param {int} delay - milliseconds that should wait before each call
@param {int} lifetime - if set, clearInterval will be called after `lifetime` milliseconds
979427
function Interval(func, options) {
    this.func = func;
    this.delay = options.delay || 16;
    this.lifetime = options.lifetime;
    this.useRequestAnimationFrame = options.useRequestAnimationFrame && window.requestAnimationFrame && window.cancelAnimationFrame;
    this.interval = null;
    this.gcTimeout = null;
}
47345
function wait() {
        var isDone = false;
        var start = new Date().getTime();

        var interval = setInterval(() => {
            var now = new Date().getTime();
            if ((now - start) >= _retryInterval){
                clearInterval(interval);
                isDone = true;
            }
        }, 50);

        deasync.loopWhile(() => !isDone);
    }
54862
function throttle(func, ms) {
    var isThrottled = false,
      savedArgs,
      savedThis;

    function wrapper() {
      if (isThrottled) { // (2)
        savedArgs = arguments;
        savedThis = this;
        return;
      }

      func.apply(this, arguments); // (1)
      isThrottled = true;

      setTimeout(function() {
        isThrottled = false; // (3)
        if (savedArgs) {
          wrapper.apply(savedThis, savedArgs);
          savedArgs = savedThis = null;
        }
      }, ms);
    }

    return wrapper;
  }
1264852
function add(opts, fn) {
    // Argument shuffling.
    if (!fn && typeof opts === 'function') {
      fn = opts;
      opts = undefined;
    }
    // Default options.
    opts = opts || {};
    opts.interval = opts.interval || 15 * 1000;
    opts.jitter = opts.jitter || 0.2;
    // Flag for stopping repeating interval.
    var stopFlag = false;
    // Recursive function.
    function rec() {
      // Start a new promise.
      return Promise.fromNode(function(cb) {
        // Apply jitter to interval to get next timeout duration.
        var duration = applyJitter(opts.jitter, opts.interval);
        // Init a timeout.
        setTimeout(function() {
          // Run handler function.
          return $q.try(fn)
          // Handle errors.
          .catch(function(err) {
            return errorHandler(err);
          })
          // Resolve promise.
          .nodeify(cb);
        }, duration);
      })
      // Recurse unless top flag has been set.
      .then(function() {
        if (!stopFlag) {
          return rec();
        }
      });
    }
    // Hold onto promise returned by recursive function so caller can wait on it.
    var prm = rec();
    // Return micro api so called can turn it off and wait for it to finish.
    var api = {
      fn: fn,
      stop: function() {
        // Tell recursive function to stop.
        stopFlag = true;
        // Return promise.
        return prm;
      }
    };
    // Add api to list of apis.
    fns.push(api);
    // Return api.
    return api;
  }
312288
async function waitForEvent(env, event, breakerFunction, timeout = 5000, interval = 10) {
    const { type, urlPattern } = event;
    let intervalId, timeoutId;
    await new Promise((resolve, reject) => {
        const callback = {
            fn: ({ error }) => {
                clearTimeout(timeoutId);
                clearInterval(intervalId);
                if (error) {
                    reject(error);
                } else {
                    resolve();
                }
            },
            urlPattern,
        };

        timeoutId = setTimeout(() => {
            env.removeCallback(type, callback);
            clearInterval(intervalId);
            reject(new Error('Page navigation timeout'));
        }, timeout);

        intervalId = setInterval(() => {
            if (breakerFunction()) {
                clearTimeout(timeoutId);
                clearInterval(intervalId);
                env.removeCallback(type, callback);
                reject(new Error('Function was terminated by breaker'))
            }
        }, interval);

        env.addCallback(type, callback);
    });

    if (type === 'navigation') {
        await env._injectFiles(env._getVendors());
    }
}
283546
function nanotick () {
  var callbacks = []
  var interval = false

  return function tick (cb) {
    assert.equal(typeof cb, 'function', 'nanotick.tick: cb should be a function')

    var isAsync = false

    executeAsync(function () {
      isAsync = true
    })

    return function wrappedTick () {
      var length = arguments.length
      var args = new Array(length)
      for (var i = 0; i < length; i++) args[i] = arguments[i]

      if (isAsync) {
        cb.apply(cb, args)
      } else {
        executeAsync(function () {
          cb.apply(cb, args)
        })
      }
    }
  }

  function executeAsync (cb) {
    callbacks.push(cb)

    if (!interval) {
      interval = true
      delay(function () {
        while (callbacks.length > 0) {
          callbacks.shift()()
        }
        interval = false
      })
    }
  }
}
1366694
function run() {
  const current = now();
  const queue = timeoutQueue.slice();
  let interval = INTERVAL_MAX;

  timeoutQueue.length = 0;

  // Reset
  if (runRafId > 0 || runTimeoutId > 0) {
    stop();
  }

  for (let i = queue.length - 1; i >= 0; i--) {
    const item = queue[i];

    if (!item.cancelled) {
      const duration = item.time - current;

      if (duration <= 0) {
        if (isDev) {
          debug('timeout triggered for "%s" at %s', item.id, new Date().toLocaleTimeString());
        }
        item.fn.apply(item.fn, item.args);
      } else {
        // Store smallest duration
        if (duration < interval) {
          interval = duration;
        }
        timeoutQueue.push(item);
      }
    }
  }

  // Loop
  if (timeoutQueue.length > 0) {
    // Use raf if requested interval is less than cutoff
    if (interval < INTERVAL_CUTOFF) {
      runRafId = raf(run);
    } else {
      runTimeoutId = setTimeout(run, interval);
    }
  }
}
175003
private void configureRetryIntervalFunction(BackendProperties properties, RetryConfig.Builder<Object> builder) {
		if (properties.getWaitDuration() != 0) {
			long waitDuration = properties.getWaitDuration();
			if (properties.getEnableExponentialBackoff()) {
				if (properties.getExponentialBackoffMultiplier() != 0) {
					builder.intervalFunction(IntervalFunction.ofExponentialBackoff(waitDuration, properties.getExponentialBackoffMultiplier()));
				} else {
					builder.intervalFunction(IntervalFunction.ofExponentialBackoff(properties.getWaitDuration()));
				}
			} else if (properties.getEnableRandomizedWait()) {
				if (properties.getRandomizedWaitFactor() != 0) {
					builder.intervalFunction(IntervalFunction.ofRandomized(waitDuration, properties.getRandomizedWaitFactor()));
				} else {
					builder.intervalFunction(IntervalFunction.ofRandomized(waitDuration));
				}
			} else {
				builder.waitDuration(Duration.ofMillis(properties.getWaitDuration()));
			}
		}
	}
1094799
function (milliseconds) {
            var deferred,
                timer = setTimeout(function () {
                    deferred.emitSuccess();
                }, milliseconds),
                canceller = function () {
                    clearTimeout(timer);
                };
            deferred = new Deferred(canceller);
            return deferred.getPromise();
        }
334620
function () {
                    // TODO Use requestAnimationFrame instead of setInterval
                    // https://developer.mozilla.org/en-US/docs/Web/API/window.requestAnimationFrame
                    this.show();
                    var self = this;
                    intervalCounterId = setInterval(function () {
                        if (isNaN(count)) {
                            clearInterval(intervalCounterId);
                            count = 0;
                            self.hide();
                        } else {
                            var remaining = 100 - count;
                            count = count + (0.15 * Math.pow(1 - Math.sqrt(remaining), 2));
                            self.updateCount(count);
                        }
                    }, 200);
                }
174336
function throttle(callback, delay) {
    var previousCall = new Date().getTime();
    return function() {
      var time = new Date().getTime();

      if ((time - previousCall) >= delay) {
        previousCall = time;
        callback.apply(null, arguments);
      }
    };
  }
1019556
def delay(self, func, args=None, kwargs=None, queue=None,
              hard_timeout=None, unique=None, lock=None, lock_key=None,
              when=None, retry=None, retry_on=None, retry_method=None,
              max_queue_size=None):
        

        task = Task(self, func, args=args, kwargs=kwargs, queue=queue,
                    hard_timeout=hard_timeout, unique=unique,
                    lock=lock, lock_key=lock_key,
                    retry=retry, retry_on=retry_on, retry_method=retry_method)

        task.delay(when=when, max_queue_size=max_queue_size)

        return task
409782
function delay(timeout, value) {
        if (timeout < 0) {
            return value;
        }

        var future = new Future();
        setTimeout(function () {
            future.resolve(value);
        }, timeout);
        return future;
    }
931573
function Timer(timeout, timeoutCallback) {
  this.finalTime = false;
  this.time = Date.now();
  this.TimerFunction = setTimeout(timeoutCallback, timeout);
}
61200
function delayWhen(delayDurationSelector, subscriptionDelay) {
    if (subscriptionDelay) {
        return function (source) {
            return new SubscriptionDelayObservable(source, subscriptionDelay)
                .lift(new DelayWhenOperator(delayDurationSelector));
        };
    }
    return function (source) { return source.lift(new DelayWhenOperator(delayDurationSelector)); };
}
158794
function waitUntil(fun) {
    var timeout = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;
    var interval = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 20;

    var timedOut = false;
    var ok = false;

    if (timeout !== 0) (0, _wait2['default'])(timeout).then(function () {
        return timedOut = true;
    });

    return new Promise(function (resolve, reject) {
        var runLoop = function runLoop() {
            if (ok) {
                resolve();
                return;
            }
            if (timedOut) {
                reject(new Error('AsyncTestUtil.waitUntil(): reached timeout of ' + timeout + 'ms'));
                return;
            }
            (0, _wait2['default'])(interval).then(function () {
                var value = (0, _promisify2['default'])(fun());
                value.then(function (val) {
                    ok = val;
                    runLoop();
                });
            });
        };
        runLoop();
    });
}
1126476
function tickify(fn, {delay} = {}) {
  delay = delay || 10;
  return function() {
    return setTimeout(() => fn.apply(this, arguments), delay);
  };
}