Skip to content

Instantly share code, notes, and snippets.

@alexTitakoff
Created December 25, 2018 23:41
Show Gist options
  • Save alexTitakoff/1688966de21318b159b44cccdf48e5df to your computer and use it in GitHub Desktop.
Save alexTitakoff/1688966de21318b159b44cccdf48e5df to your computer and use it in GitHub Desktop.
не секретный гист waitFunction
let conditionParam = 0
function conditionFunc() { // Какая то функция или действие в интерфейсе состояние которого мы ожидаем
if (conditionParam != 5) {
setTimeout(() => {
conditionParam++
console.log('conditionFunc')
return conditionFunc()
}, 3000)
}
}
conditionFunc()
function waitCycleFunc(cycles,delay,func) {
let cycle = 0
function waitCheck () {
if (conditionParam === 5) {
func()
} else if (cycle !== cycles ) {
setTimeout(() => {
cycle++
console.log(conditionParam, 'conditionParam')
console.log(func.name + ' not executed')
return waitCheck()
}, delay);
}
}
waitCheck()
}
function executionFunc() {
console.log('executionFunc executed')
}
waitCycleFunc(10,1000, executionFunc)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment