Skip to content

Instantly share code, notes, and snippets.

@caike
Last active August 29, 2015 14:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save caike/d76a3fdecd0a29bbab67 to your computer and use it in GitHub Desktop.
Save caike/d76a3fdecd0a29bbab67 to your computer and use it in GitHub Desktop.
async calls
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