Skip to content

Instantly share code, notes, and snippets.

@andrIvash
Created December 21, 2017 20:23
Show Gist options
  • Select an option

  • Save andrIvash/618d6d76c45245deeb0d4c8754a55fce to your computer and use it in GitHub Desktop.

Select an option

Save andrIvash/618d6d76c45245deeb0d4c8754a55fce to your computer and use it in GitHub Desktop.
promise waterfall
function delay(ms) {
return () => {
return new Promise(resolve => setTimeout(() => {
resolve();
console.log('!!!');
}, ms));
}
}
function waterfall(list) {
return list.reduce((promise, fn) => {
return promise.then(() => fn());
}, Promise.resolve());
}
waterfall([delay(3000), delay(1000), delay(2000)]);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment