Skip to content

Instantly share code, notes, and snippets.

View zlargon's full-sized avatar
:electron:
Focusing

Leon Huang zlargon

:electron:
Focusing
  • Boston, MA
View GitHub Profile
@zlargon
zlargon / [Javascript] Demo asynchronous programming in for-loop .js
Last active August 29, 2015 14:08
Show how to handle the asynchronous function in the for-loop. until all the function complete, then print out "all the tasks are completed"
var demo = function (num, callback) {
var counter = 0;
var checkTasksComplete = function() {
counter++;
if (counter === num) {
callback();
}
};
// Closure: create a new function with console.log(string)