Really, I've tried all ways, but I fail to find the solution.
As no English, and I'm using the google translator, I will explain the same thing several times in a row.
1º Try the For loop will wait until everything is finished within
2º I try to know that city is doing OK on an external web request. And like many cities, I need to break the cycle once I check the first city ok.
3º I need to go a json and execute an action while running and wait till it finishes to follow. Then get out of the cycle at any time.
I've been testing with several codes, but present here for better understanding.
---------------------------------------------------------------------
var city =
[
{'city':'madrid'},
{'city':'barcelona'},
{'city':'valencia'},
{'city':'malaga'}
];
var vBreak = 0;
for (i in city){
request('example.there-city.com/' + city[i].city ,function (error, response, read) {
if (read == 'OK') { vBreak = 1}
});
if (vBreak == 1){ break;}
}
var city =
[
{'city':'madrid'},
{'city':'barcelona'},
{'city':'valencia'},
{'city':'malaga'}
];
var vBreak = 0;
for (i in city){
(function(i) {
request('example.there-city.com/' + city[i].ciudad ,function (error, response, read) {
if (read == 'OK') { vBreak = 1}
});
})(i);
if (vBreak == 1){ break;}
}
Thank you