Skip to content

Instantly share code, notes, and snippets.

@lourenzo
Created July 22, 2015 21:19
Show Gist options
  • Save lourenzo/a9bfd913fb690022ad5e to your computer and use it in GitHub Desktop.
Save lourenzo/a9bfd913fb690022ad5e to your computer and use it in GitHub Desktop.
Simple Browser Utility function to run sequenced functions
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