I have few functions which should be executed one by one in loop and with delay. Here is the code I have:
function func1() {
for (var i = 0; i < 3; i++) {
func2().then(); // await in loop until func2() completed
}
}
function func2() {
return new Promise(succes) {
for (var i = 0; i < 10; i++) {
function3().then(); //wait untill function3 and then continue looping
}
success();
}
}
function function3() {
return new Promise(function(ready) {
setTimeout(function() {
// do some stuff
ready();
}, 2000);
});
}
But it doesn't work. What I should change?