I'm trying to understand async-await
but it doesn't matter how much I read about it it still performs different from what I expect.
Here is my code:
async function exampleFunction(myArray){
for await (let item of myArray) {
console.log('ITERATION')
let dataInfo = await getDataInfo(item.data)
console.log(dataInfo)
}
}
async function getDataInfo(dataPoint){
let info1 = await awaitableFunction1(dataPoint)
let info2 = await awaitableFunction2(dataPoint)
return [info1,info2]
}
If I pass exampleFunction()
an array of 3 items (3 resolved values, NOT 3 promises), I would expect it to log:
ITERATION
ITERATION
ITERATION
[dataInfo1]
[dataInfo2]
[dataInfo3]
Instead it logs:
ITERATION
[dataInfo1]
ITERATION
[dataInfo2]
ITERATION
[dataInfo3]
Proving that the code is not asynchronous. What is wrong with it? Thanks