Hi I was wondering how I could await a void function.
I tried the following (mock up):
async function asyncer() {
setTimeout(() => {
console.log("async msg")
}, 0)
}
async function helloer() {
await asyncer()
console.log("hello")
}
helloer()
This however doesn’t work, so I tried the following :
async function asyncer() {
setTimeout(() => {
console.log("async msg")
}, 0)
return true
}
async function helloer() {
let ready = await asyncer()
if (ready) {
console.log("hello")
}
}
helloer()
Still "hello" is still logged before "async msg".
Does anyone know a solution to this problem.
Thanks in advance.
>Solution :
async/await is a syntax sugar for promise.then, so create a Promise.resolve or smth to enter in async flow and then use async/await