Asynchronous calculation is possible?

Hi,
I’m creating a game where for each score marked you need a pretty long calculation (about 1 or 2 seconds).
I don’t need the result immediatly since an animation is executed in the meanwhile, but the problem is that the game freeze until the calculation isn’t done.

So, is there any way for executing such a calculation “asynchronously” ?
If yes, how can I know when the calculation is done and recovery the result?

Use the javascript event, and async function and worker in js too. Otherwise i have no idea.

1 Like

What does it means “async function and worker in js”? Is there any reference?

For making an async function, you can do something like

(async function() {
    // Some part of the calculation
    await longPartOfTheCalculation();
    // Some other calculations
    // Something to show the result
})()

Imagine all await statements as the place where you tell the software “pause the calculation here and render the current frame before continuing calculation”

(I say everything out of memory but I could be wrong, test a bit and research online too to verify what I say)

2 Likes