I have a component which takes some inputs from a user and then does some calculations (which takes some seconds). I want to use async/await block to handle this in UI. Here is the main part of the code:
async function computePV(data) {
return await pv(data);
}
function compute(e) {
console.log("button clicked")
pcvpromise = computePV(data);
console.log("promise created")
}
$: console.log(pcvpromise)
Here function pv()
is the one that does the calculations. Method compute()
is called by on:click event from button. My expectations:
- Show message "button clicked"
- Show message "promise created"
- Show the created promise
- Wait until the calculations are done and resolve the promise
Reality:
- Show message "button clicked"
- Wait until the calculations are done
- Show message "promise created"
- Show the created promise
The code is a copy of code from Svelte tutorial about async/await I just changed a couple of minor things. What am I doing wrong?