I have two functions on my backend that essentially do the following:
const function2 = async(var1, var2, var3, var4) => {
var x = await function1(var1);
console.log(x);
}
var function1 = async function (var1){
var array = [];
var1.forEach(async function(val){
try{
smallarr = await Item.find({
val:val.x
})
array.push(smallarr);
}
})
console.log(array);
return array;
}
However, the log statement in the function2 is getting called before the log statement in function1. I'm going off of the following example from an old StackExchange thread
What is going wrong in my code? What am I not understanding about async/await? I can provide the actual code instead of the cute example, but they're pretty big functions.