Created
July 22, 2015 21:19
-
-
Save lourenzo/a9bfd913fb690022ad5e to your computer and use it in GitHub Desktop.
Simple Browser Utility function to run sequenced functions
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
function waterfall() { | |
var args = [].slice.call(arguments); | |
var next = args.shift(); | |
if (!next) return; | |
next(); // @todo: check if it's a Promise | |
setTimeout(function() { waterfall.apply(null, args); }, 100); | |
} | |
// Sample usage: | |
waterfall( | |
function () { | |
console.log('Do this!'); | |
}, | |
function () { | |
console.log('Now do that!'); | |
} | |
); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment