Your long-term calculation blocks the browser, which will never be a good idea. Therefore, you should put it in a web artist.
These days it is better to write asynchronous code with asynchronous tools like promises. The general pseudo-code level approach is used here:
// Create a promise which fulfills after some
Writing a worker remains in the form of an exercise.
Using Asynchronous Functions
You can also express this more purely using asynchronous functions, if your environment supports it, as follows:
async function calcAndWait() { const result = waitWorker(); // Kick off computation. await timeout(ms); // Wait for two seconds. output(await result); // Wait for computation to finish and output. }
user663031
source share