Created
October 27, 2015 00:41
-
-
Save balanza/7ed7b8e32024ce383276 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//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