Created
          May 28, 2018 13:57 
        
      - 
      
 - 
        
Save fakenickels/2723f1b450c7fd2086f3f15a980204e9 to your computer and use it in GitHub Desktop.  
    Waterfall helper
  
        
  
    
      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
    
  
  
    
  | const mail = (foo, t) => new Promise((resolve) => setTimeout(() => { console.log(foo); resolve() }, t)) | |
| async function doThing() { | |
| const items = ['foo', 'bar', 'buz', 'fuz']; | |
| await waterfall(items.map((item) => async () => { await mail('mailing' + item, 4000); })) | |
| await mail("end", 1000) | |
| } | 
  
    
      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
    
  
  
    
  | const waterfall = (promises) => promises.reduce((wfall, currentPromise) => wfall.then(currentPromise), Promise.resolve()) | 
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment