I have a function that has a $.each to loop over keys of an object and do stuff. within this loop i am calling a function which in turns makes a call to the server to get some data and does things with it in a callback. these calls are asynchronous so the $.each does not wait for the data to come and the callback to do what its supposed to and keeps iterating. How do i make the $.each loop wait till i complete my operation and then continue.
$.each(messages,function(key) {
//do something
if(some Condition) {
getfromserver(token,myCallback); }
//do something
});
function myCallback(data)
{
//do something with data
}