Repository URL to install this package:
|
Version:
3.12.2 ▾
|
/**
* Run fn recursively with intervals until fn is defined.
*/
var recursiveFnCall = function recursiveFnCall() {
var _ref = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},
_ref$delay = _ref.delay,
delay = _ref$delay === void 0 ? 500 : _ref$delay,
getFn = _ref.getFn,
_ref$maxAttempts = _ref.maxAttempts,
maxAttempts = _ref$maxAttempts === void 0 ? 20 : _ref$maxAttempts;
var timeoutCount = 0;
var recursiveTimeout = function recursiveTimeout() {
var _delay = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : delay;
setTimeout(function () {
timeoutCount++;
var fn = getFn();
if (typeof fn === 'function') {
fn();
} else if (timeoutCount <= maxAttempts) {
recursiveTimeout();
}
}, _delay);
};
recursiveTimeout(0);
};
export default recursiveFnCall;