foreach-promise
handle series of nested forEachs as one big promise
If you are tired of handling js asynchronous forEachs with counters and stuff, this little module will help you.
Install
npm install foreach-promise --save
Usage
const forEP = require('foreach-promise'); forEP(array, callback) : returns a Promise that resolves when all the data is traversed callback can be a function which returns another forEP execution. (for foreach nesting) callback will be called with element, index, array arguments.
Let's say you're coding a function to generate names with nouns and adjectives, maybe you code something like the function below to do this.
{ const namesList = ; return { let nounsLen = nounslength; nouns; }; }
But you really dont wanna do this everytime you need some data manipulation like this.
And this can be a mess as the number of nested forEachs increases.
So, through this module, which I call: foreach-promise , you can implement the function above like the code below:
const forEP = ;{ const namesList = ; return { ; }; }
For more examples, take a look at the tests within test folder.