Skip to content

Instantly share code, notes, and snippets.

@balanza
Created October 27, 2015 00:41
Show Gist options
  • Save balanza/7ed7b8e32024ce383276 to your computer and use it in GitHub Desktop.
Save balanza/7ed7b8e32024ce383276 to your computer and use it in GitHub Desktop.
//array of async resources to be loaded
var paths = ['file1.xml', 'file2.xml', 'file3.xml'];
//finalizing function, to be called after all async operations are completed
var finalize = _.after(function(){
alert('this is the last execution!');
}, paths.length);
//the callback for the ajax call
var callback = function(fileIndex){
alert('this is a callback for file ' + paths[fileIndex]);
finalize();
};
//generates ajax calls
for(var i=0; i<=paths.length; i++){
ajax.get('http://foo.com/' + paths[i], _.partial(callback, i));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment