function subProcess() {
var f = [];
for (var i = 0; i < 10000; i++) {
for (var j = 0; j < 100000; j++) {}
f.push(1);
}
}
var statusElement = document.getElementById('status');
statusElement.innerHTML = "1";
subProcess();
statusElement.innerHTML += "<br/>2";
subProcess();
statusElement.innerHTML += "<br/>3";
subProcess();
statusElement.innerHTML += "<br/>4";
subProcess();
statusElement.innerHTML += "<br/>5";
subProcess();
statusElement.innerHTML += "<br/>6";
subProcess();
statusElement.innerHTML += "<br/>7";
subProcess();
statusElement.innerHTML += "<br/>8";
statusElement.innerHTML = "finished";
<div id='status'></div>
I have a simple wish, that i can solve, but my question is it the right way.
I have process which takes time. The process is divided into several sub process. When each sub process ends i want to write it at some paragraph element.
The problem is that the paragraph is not updating till the big process ends and that because the browser is occupied and when it will be free it will update the DOM.
I know I can simply put each sub process in timeout with 10 milliseconds or something like this, and it is doing the job.
The question is it the only way ? Is it a function that tells the browser do your work and tell when u finished ?
For ex.
// process start
// writing the status to paragraph
// wait till browser update the dom elements
// sub process 1 start
// writing the status to paragraph
// wait till browser update the dom elements
// sub process 2 start
// writing the status to paragraph
// wait till browser update the dom elements
// sub process 3 start
// writing the status to paragraph
// wait till browser update the dom elements
// process 1 ends
My problem is that the process time is important for me. and i see when i put timeout with 0 milliseconds it is not working for some reason. so 10 miliseconds for each sub process can be summarized into half a second.