Last active
May 24, 2018 21:13
-
-
Save popovkos/132548d52758c68cf916bd76f29a3cb9 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
async function someFunction() { | |
const myArray = [1, 2, 3]; | |
const connection = mysql.createConnection({ options }); // create db connection | |
let finalArray = []; | |
await asyncForEach(async (value) => { | |
const finalValue; | |
const asyncFunctionValue = await asyncFunction(connection, value); // async function that returns a promise | |
finalValue.asyncFunctionValue = asyncFunctionValue; // doing assignment operations with resolved value | |
finalArray.push(finalValue); // pushing each value to an array | |
}); | |
return functionThatUsesResolvedValues(finalArray); // passing array of values futher | |
}; | |
async function asyncForEach(array, callback) { // modifies version of forEach, taken from https://codeburst.io/javascript-async-await-with-foreach-b6ba62bbf404 | |
for (let index = 0; index < array.length; index += 1) { | |
await callback(array[index], index, array); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment