Skip to content

Instantly share code, notes, and snippets.

@cirocosta
Created August 29, 2014 03:47
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 cirocosta/b09165bf96eca12f5f7f to your computer and use it in GitHub Desktop.
Save cirocosta/b09165bf96eca12f5f7f to your computer and use it in GitHub Desktop.
Executes a list of functions with a given delay between each
var timedFuncs = [
[null, function () {
console.log('First!');
}],
[1000, function () {
console.log('Second!');
}],
[400, function () {
console.log('Third!');
}],
];
function timedExec (list) {
var current = 0;
return function _temp () {
list[current][1]();
if (++current in list)
setTimeout(_temp, list[current][0]);
}
}
setTimeout(timedExec(timedFuncs), 300);
// 300 ms, then : First!
// 1s then: Second!
// 400ms then: Third!
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment