Skip to content

Instantly share code, notes, and snippets.

@jonlow
Last active August 30, 2016 02:45
Show Gist options
  • Save jonlow/c110a4952bd3ec5e91d3 to your computer and use it in GitHub Desktop.
Save jonlow/c110a4952bd3ec5e91d3 to your computer and use it in GitHub Desktop.
var aFunc = [];
function callback(delay) {
setTimeout(function() {
if (aFunc.length > 0) {
console.log(aFunc.length)
aFunc[0]();
aFunc.shift();
} else {
console.log('end');
}
}, delay)
}
var an1 = function() {
callback(100)
}
var an2 = function() {
callback(2000)
}
var an3 = function() {
callback(600)
}
aFunc = [an1, an2, an3];
callback(1000);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment