Skip to content

Instantly share code, notes, and snippets.

@vancouverwill
Created May 24, 2013 21:32
Show Gist options
  • Save vancouverwill/5646661 to your computer and use it in GitHub Desktop.
Save vancouverwill/5646661 to your computer and use it in GitHub Desktop.
javascript limited time interval using timeout
function setTimedOutInterval(totalTime, intervalTime, callBackFunction) {
intervalId = setInterval(function () {
console.log('check B');
if (finished === true) {
console.log('B finished = true');
clearInterval(intervalId);
callBackFunction();
}
}, intervalTime);
var tmpDelayB = setTimeout(function () {
clearInterval(intervalId);
console.log('time out');
}, totalTime);
}
setTimedOutInterval(4000, 500, finished);
function finished() {
console.log('finished!!');
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment