I currently use setInterval and a wait flag to process this collection. Is there a cleaner way?
var wait = false;
var processInterval = setInterval(function(){
if(!wait){
var currentVideo = videos.shift();
if(currentVideo){
wait = true;
validateSongById(currentVideo.videoId, function(result){
wait = false;
if(result){
clearInterval(processInterval);
callback(currentVideo);
return;
}
});
}
}
}, 200);