Last active
August 29, 2015 14:24
-
-
Save caike/d76a3fdecd0a29bbab67 to your computer and use it in GitHub Desktop.
async calls
This file contains 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
fetchProfile(1, function(){ | |
console.log("Callback 1"); | |
}); | |
fetchProfile(2, function(){ | |
console.log("Callback 2"); | |
}); | |
fetchProfile(3, function(){ | |
console.log("Callback 3"); | |
}); | |
fetchProfile(4, function(){ | |
console.log("Callback 4"); | |
}); | |
fetchProfile(5, function(){ | |
console.log("Callback 5"); | |
}); | |
fetchProfile(6, function(){ | |
console.log("Callback 6"); | |
}); | |
fetchProfile(7, function(){ | |
console.log("Callback 7"); | |
}); | |
fetchProfile(8, function(){ | |
console.log("Callback 8"); | |
}); | |
function fetchProfile(n, callback){ | |
console.log("Running ", n); | |
if(n === 2){ | |
setTimeout(function(){ | |
callback(); | |
}, 800); | |
}else{ | |
setTimeout(function(){ | |
callback(); | |
}, 200); | |
} | |
} | |
/* | |
Output: | |
Running 1 | |
Running 2 | |
Running 3 | |
Running 4 | |
Running 5 | |
Running 6 | |
Running 7 | |
Running 8 | |
Callback 1 | |
Callback 3 | |
Callback 4 | |
Callback 5 | |
Callback 6 | |
Callback 7 | |
Callback 8 | |
Callback 2 | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment