Created
December 21, 2017 20:23
-
-
Save andrIvash/618d6d76c45245deeb0d4c8754a55fce to your computer and use it in GitHub Desktop.
promise waterfall
This file contains hidden or 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 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