Skip to content

Instantly share code, notes, and snippets.

@popovkos
Last active May 25, 2018 07:29
Show Gist options
  • Save popovkos/8f09aa0fa293babb3ec86518a7502851 to your computer and use it in GitHub Desktop.
Save popovkos/8f09aa0fa293babb3ec86518a7502851 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.map(async(value) => { // map instead of forEach
const result = await asyncFunction(connection, value);
finalValue.asyncFunctionValue = result.asyncFunctionValue;
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