Answer the question
In order to leave comments, you need to log in
How to make a loop wait for a function?
Good afternoon. There are 2 functions:
function showUser(data) {
for (var k = 0; k < 10; k++) {
arrayMess = [];
getMes(data[k][0],data[k][0] );
}
}
function getMes(data1,data2) {
var i = 200;
var timerId = setInterval(function() {
addScript('https://api.vk.com/method/execute?code=' + encodeURIComponent('var mes = API.messages.getHistory({"user_id":'+ data1 +',"count": 200});var i = '+ i +';var arr = [];arr = arr + [email protected]_id;while (i < ('+ i +' + 4800) ) {var mes = API.messages.getHistory({"offset":i,"user_id":'+ data1 +',"count": 200});arr = arr + [email protected]_id;i = i + 200;}return {"count":mes.count,"users":arr};') + '&access_token=' + token + '&callback=showMess&v=5.69');
if (data2 == arrayMess.length) {
clearInterval(timerId);
}
i = i + 5000;
}, 1000);
}
Answer the question
In order to leave comments, you need to log in
With async/await you can do this: https://jsfiddle.net/rockon404/ewpbd4bv/
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question