Created
December 25, 2018 23:41
-
-
Save alexTitakoff/1688966de21318b159b44cccdf48e5df to your computer and use it in GitHub Desktop.
не секретный гист waitFunction
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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