Skip to content

Instantly share code, notes, and snippets.

@agscala
Last active August 29, 2015 14:25
Show Gist options
  • Save agscala/e8023d62c94b50561e2e to your computer and use it in GitHub Desktop.
Save agscala/e8023d62c94b50561e2e to your computer and use it in GitHub Desktop.
var seen_images = [...]
var process_image = function() { /* render */ };
var find_image = function(page_num, callback) {
$.get('url', {page: page_num}, function(image_list) {
var new_image_found = false;
for(var i = 0; i < image_list.length; ++i) {
if(seen_images.indexOf(image_list[i]) == -1) {
new_image_found = true;
callback(image_list[i]);
break;
}
}
if(new_image_found === false) {
find_image(page_num + 1, callback)
}
}
}
find_image(params, process_image);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment