I have some example code, but I can't figure out why the console is logging things out of order.
async function myAsyncFunction() {
setTimeout(() => { console.log("1st"); return "something"; }, 500);
}
async function mainline() {
let promise = new Promise((resolve, reject) => {
setTimeout(() => { console.log("0th"); resolve(); }, 500);
});
promise.then(async () => {
return await myAsyncFunction();
})
.then((string) => {
console.log(string);
console.log("2nd");
});
}
mainline();
The console logs:
> 0th
> undefined
> 2nd
> 1st
So clearly my mainline isn't waiting to resolve the async function. What did I do wrong?