Skip to content

Instantly share code, notes, and snippets.

@phuoctamm
Forked from popovkos/loops_promises_3.js
Created January 28, 2020 15:36
Show Gist options
  • Save phuoctamm/c0ca79fa74414fd5484fdcf3a5da0033 to your computer and use it in GitHub Desktop.
Save phuoctamm/c0ca79fa74414fd5484fdcf3a5da0033 to your computer and use it in GitHub Desktop.
async function someFunction() {
const myArray = [1, 2, 3];
const connection = mysql.createPool({ options });
let finalArray = [];
myArray.forEach((value) => { // standard forEach
finalArray.push(asyncFunction(connection, value).then((result) => {
finalValue.asyncFunctionValue = result.asyncFunctionValue; // giving instructions
return finalValue; // important to return the value
}));
});
const resolvedFinalArray = await Promise.all(finalArray); // resolving all promises
return functionThatUsesResolvedValues(resolvedFinalArray);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment