Node.js Patterns: Sequential Iteration Pattern
The sequential iteration pattern is best used if you have an array of elements which you want to feed into an async function.
The following example has a list of filenames.
The filenames are feeded with a foreach loop to an async function that reads out the content of the files.
The contents of the files are stored in an array and when the last task is processed the last resolved value gets passed to the last then.
file1.txt1
This is content from file1.
file2.txt1
This is content from file2.
sequential-iteration-promise.js
1 | /******************************************************************************* |