Created
March 25, 2018 08:53
-
-
Save Rwin90/4e322bcec691d629f886e8b99a7ee56b to your computer and use it in GitHub Desktop.
a generic function that sequencialy run a function on a promiss array
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 waitForEach = (processFunc , [head, ...tail]) => | |
!head | |
? Promise.resolve() | |
: processFunc(head).then(waitForEach(processFunc , tail)); | |
// example of usage | |
function proceessAllUser() { | |
const sql = 'SELECT ID FROME users'; | |
return db.query(sql , []) | |
.then( users => waitForEach(user => processUser(user.id) , users)) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment