Attempting to use $.Deferreds in place of setTimeOut which I was using prior. I'm running into an issue, as writer() isn't actually done, because the $.each are still looping at the time printer() is called.
I haven't seen an example of $.Deferreds with loops. Obviously the below is wrong, and I'm betting it has to do with the resolve - any help would be appreciated.
$.when( writer() ).done(function() {
printer();
});
function writer(){
var deferred = new $.Deferred();
if(x){
$("a").each(function () {...});
}
if(y){
$("img").each(function () {...});
}
if(z){
$("div").each(function () {...});
}
deferred.resolve();
return deferred.promise();
}
function printer(){...}