Created
August 29, 2014 03:47
-
-
Save cirocosta/b09165bf96eca12f5f7f to your computer and use it in GitHub Desktop.
Executes a list of functions with a given delay between each
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
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