If you have completely synchronous code (without the asynchronous operations that you are trying to track completion), you DO NOT want to use promises.
Trying to use promises with synchronous code only adds unnecessary complexity to the logic of the code and slows down the execution of your code. When using all the synchronous code, there is nothing to wait for completion or agreement with the completion, so you can simply execute your code and immediately get the result. Adding promises just complicates your code unnecessarily.
In addition, Promise.all() expects you to pass it an array of promises, and not an array of values similar to the one you are doing, in addition to the unnecessary, what you did is also wrong.
So, there is no reason to not just do this:
.... for (var i = 0; i < rows.length; i++) { // loop over a CSV file by line var cell = rows[i].split(/;/) var origin = cell[1] var destination = cell[2] var id = cell[0] // operate on id, destination and origin here // no need to wait on a promise before doing so } ...
The promise will be used with asynchronous operations, such as database operations, file operations, network operations, synchronization operations, etc. You can use them to know when a single asynchronous operation is being performed or to coordinate several operations (some of which are asynchronous).
source share