Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.