Let's say we have two Async functions:
function someOtherAsyncFunc() {
return new Promise((resolve) => {
setTimeout(() => {
resolve()
}, 3000)
})
}
async function asyncFunc() {
const asyncData = await someOtherAsyncFunc()
console.log("sync task that doesn't depend on the asynchronous data")
asyncData.doSomething()
}
Is there a way not to pause the function execution until only the asynchronous variable is referenced later on in the code?
- Get the asynchronous data asynchronously
- Continue the execution until that data is needed and then 'await' it