Skip to content

Instantly share code, notes, and snippets.

@vancouverwill
Last active December 17, 2015 17:39
Show Gist options
  • Save vancouverwill/5647118 to your computer and use it in GitHub Desktop.
Save vancouverwill/5647118 to your computer and use it in GitHub Desktop.
multi level interval boolean check with timeout
function successFunction() {
console.log('begin nike button');
}
function failFunction() {
console.log('shit hit the fan');
}
function setTimedOutInterval(totalTime, intervalTime, callBackFunction) {
var args = Array.prototype.slice.call(arguments, 3);
console.log(arguments);
console.log(totalTime);
var tmpDelayB = setTimeout(function () {
clearInterval(intervalId);
console.log('function over');
callBackFunction.apply(null, args);
}, totalTime);
var intervalId = setInterval(function () {
console.log('check ');
if (finished === true) {
console.log('B finished = true');
clearInterval(intervalId);
clearTimeout(tmpDelayB)
successFunction();
}
}, intervalTime);
}
var finished = false
var sdkDelay = setTimeout(function () {
console.log('done');
finished = true;
}, 10000);
setTimedOutInterval(4000, 100, setTimedOutInterval, 10000, 1000, failFunction);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment