make sure a function is only called once within the given amount of time
@param {Function} fn the function to throttle
@param {number} threshold time limit for throttling
 must use function to keep this context
420301
function _throttle (fn, threshold) {
        var _this = this;
        if (threshold === void 0) { threshold = 250; }
        // check function
        if (typeof fn !== 'function') {
            throw new Error('You must provide a function as the first argument for throttle.');
        }
        // check threshold
        if (typeof threshold !== 'number') {
            throw new Error('You must provide a number as the second argument for throttle.');
        }
        var lastEventTimestamp = null;
        return function () {
            var args = [];
            for (var _i = 0; _i < arguments.length; _i++) {
                args[_i - 0] = arguments[_i];
            }
            var now = Date.now();
            if (lastEventTimestamp === null || now - lastEventTimestamp >= threshold) {
                lastEventTimestamp = now;
                fn.apply(_this, args);
            }
        };
    }
668877
function (key, timeInterval, limit) {
        //Validate rate limiter settings
        if (!_.isNumber(timeInterval) || parseInt(timeInterval) <= 0 || !_.isNumber(limit) || parseInt(limit) <= 0) {
            return Q.reject();
        }
        var cacheKey = Encryption.md5("MiaJSRateLimit" + key + _calculateCurrentTimeInterval(timeInterval));
        return _validateRateLimit(cacheKey, timeInterval, limit).then(function (value) {
            return Q({
                limit: limit,
                remaining: limit - value,
                timeInterval: timeInterval,
                timeTillReset: _getTimeLeftTillReset(timeInterval)
            });
        });
    }
983688
function startTimeout(func, time, self) {
  return {
    timer: setTimeout(func.bind(self), time),
    stopped: false
  };
}
111009
function once (fn) {
  var done = false
  return function (err, val) {
    if(done) return
    done = true
    fn(err, val)
  }
}
706149
function throttleTime(duration, scheduler, config) {
    if (scheduler === void 0) {
        scheduler = _scheduler_async__WEBPACK_IMPORTED_MODULE_2__["async"];
    }
    if (config === void 0) {
        config = _throttle__WEBPACK_IMPORTED_MODULE_3__["defaultThrottleConfig"];
    }
    return function (source) { return source.lift(new ThrottleTimeOperator(duration, scheduler, config.leading, config.trailing)); };
}
280725
function( min, startFunc ) {
		var self = this;

		if ( min > self.state ) {
			self._stateError( startFunc || self.requireMinState );
		}

		return self;
	}
21382
def call_only_once(func):
    
    @functools.wraps(func)
    def wrapper(*args, **kwargs):
        self = args[0]
        # cannot use hasattr here, because hasattr tries to getattr, which
        # fails if func is a property
        assert func.__name__ in dir(self), "call_only_once can only be used on method or property!"

        if not hasattr(self, '_CALL_ONLY_ONCE_CACHE'):
            cache = self._CALL_ONLY_ONCE_CACHE = set()
        else:
            cache = self._CALL_ONLY_ONCE_CACHE

        cls = type(self)
        # cannot use ismethod(), because decorated method becomes a function
        is_method = inspect.isfunction(getattr(cls, func.__name__))
        assert func not in cache, \
            "{} {}.{} can only be called once per object!".format(
                'Method' if is_method else 'Property',
                cls.__name__, func.__name__)
        cache.add(func)

        return func(*args, **kwargs)

    return wrapper
855944
function Timer(timer, clear, fn) {
      this.clear = clear;
      this.timer = timer;
      this.fns = [fn];
    }
459129
function throttle(func, wait, options) {
      var leading = true, trailing = true;
      if (!isFun(func)) throwErr('fun');
      if (isObj(options)) {
        leading = has(options, 'leading') ? !!options.leading : leading;
        trailing = has(options, 'trailing') ? !!options.trailing : trailing;
      }
      return debounce(func, wait, {
        'leading': leading,
        'maxWait': wait,
        'trailing': trailing
      });
    }
814792
def rate_limited(max_per_hour: int, *args: Any) -> Callable[..., Any]:
    """"""
    min_interval = 3600.0 / float(max_per_hour)

    def _decorate(func: Callable[..., Any]) -> Callable[..., Any]:
        things = [func.__name__]
        things.extend(args)
        key = "".join(things)
        LOG.debug(f"Rate limiter called for '{key}'.")
        if key not in LAST_CALLED:
            LOG.debug(f"Initializing entry for '{key}'.")
            LAST_CALLED[key] = 0.0

        def _rate_limited_function(*args: Any, **kargs: Any) -> Any:
            last_called = LAST_CALLED[key]
            now = time.time()
            elapsed = now - last_called
            remaining = min_interval - elapsed
            LOG.debug(f"Rate limiter last called for '{key}' at {last_called}.")
            LOG.debug(f"Remaining cooldown time for '{key}' is {remaining}.")

            if remaining > 0 and last_called > 0.0:
                LOG.info(f"Self-enforced rate limit hit, sleeping {remaining} seconds.")
                for i in tui.progress.bar(range(math.ceil(remaining))):
                    time.sleep(1)

            LAST_CALLED[key] = time.time()
            ret = func(*args, **kargs)
            LOG.debug(f"Updating rate limiter last called for '{key}' to {now}.")
            return ret

        return _rate_limited_function
    return _decorate
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;
}
396982
def call_only_once(func):
    '''
    
    '''

    def new_func(*args, **kwargs):
        if not new_func._called:
            new_func._called = True
            return func(*args, **kwargs)

    new_func._called = False
    return new_func
1234384
function doAsyncBench(fn, callback) {

		var fnOverhead,
		    pretotal,
		    result,
		    args,
		    i;

		if (benchRunning > 0) {

			// Keep function optimized by not leaking the `arguments` object
			args = new Array(arguments.length);
			for (i = 0; i < args.length; i++) args[i] = arguments[i];

			benchQueue.push(args);
			return;
		}

		benchRunning++;

		// See how many times we can get it to run for 300ms
		Collection.Function.doTime(300, fn, function(err, runs, elapsed) {

			// See how the baseline latency is like
			Blast.getEventLatencyBaseline(function(err, median) {
				asyncTest(fn, runs, median+(getFunctionOverhead(runs)*8), function asyncDone(err, result) {

					var next,
					    name;

					// Call the callback
					if (callback) {
						result.name = fn.name || '';
						callback(err, result);
					} else {
						name = fn.name || '';
						if (name) name = 'for "' + name + '" ';

						console.log('Benchmark ' + name + 'did ' + Bound.Number.humanize(result.ops) + '/s (' + Bound.Number.humanize(result.iterations) + ' iterations)');
					}

					benchRunning--;

					// Schedule a next benchmark
					if (benchRunning == 0 && benchQueue.length > 0) {

						// Get the top of the queue
						next = benchQueue.shift();

						Blast.setImmediate(function() {
							doAsyncBench.apply(null, next);
						});
					}
				});
			});
		});
	}
1126476
function tickify(fn, {delay} = {}) {
  delay = delay || 10;
  return function() {
    return setTimeout(() => fn.apply(this, arguments), delay);
  };
}
110627
function onceify(f) {
  var ran, ret;
  return function() {
    return ran ? ret : (ran=true, ret=f.apply(this,arguments));
  };
}
450858
function(func) {
		var timeout, timestamp;
		var wait = 99;
		var run = function(){
			timeout = null;
			func();
		};
		var later = function() {
			var last = Date.now() - timestamp;

			if (last < wait) {
				setTimeout(later, wait - last);
			} else {
				(requestIdleCallback || run)(run);
			}
		};

		return function() {
			timestamp = Date.now();

			if (!timeout) {
				timeout = setTimeout(later, wait);
			}
		};
	}
401144
function retry(fn) {

  return function retried() {

    var args = arguments.length ? Array.prototype.slice.call(arguments, 0, arguments.length - 1) : [];
    var done = arguments.length ? arguments[arguments.length - 1] : noop;

    var cfn = null;
    var canceled = false;

    function exec() {
      var err = arguments[0];
      if (!err || canceled) {
        done.apply(null, arguments);
      } else {
        cfn = fn.apply(null, args);
      }
    }

    args.push(exec);
    exec(true);

    return function cancel() {
      canceled = true;
      cfn.apply(null, arguments);
    };

  };

}