I need a loop that waits for an async call before continuing. Something like:
for ( /* ... */ ) {
someFunction(param1, praram2, function(result) {
// Okay, for cycle could continue
})
}
alert("For cycle ended");
How could I do this? Do you have any ideas?
You can't mix synchronous and asynchronous in JavaScript if you block the script, you block the Browser.
You need to go the full event driven way here, luckily we can hide the ugly stuff away.
EDIT: Updated the code.
This will provide us an asynchronous
loop
, you can of course modify it even further to take for example a function to check the loop condition etc.Now on to the test:
And the output: