I have read a lot of articles about the JavaScript single-threaded performance model, event-loop, and the line of events.
One thing though is not clear though. I made a bela to clarify my question:
& lt; Button onClick = "window.compute ()" & gt; Calculate & lt; / Button & gt; & Lt; Button onClick = "warning ('tax')" & gt; Do something else & lt; / Button & gt; Window.compute = function count () {var results = 0; For (var i = 0; i & lt; 100000; i ++) {for (var j = 0; j & lt; 100000; j ++) {Results = i + j; }}; Var textNode = document.createTextNode (results); Document.body.appendChild (textnode);
}
If you click the "Calculate" button, it will take some time and the page will be blocked. But if you click on the "do something else" button, while the page is still hanging, it will still be added to the queue and it will be executed after our calculation is finished.
So if JS is single-threaded, then is the UI event put in the event line while we are doing some more computing?
Single-threaded UI events are putting in the event queue, while we do something else Computing?
Not obviously :-) This is one of the other threads in a browser, which is responsible for this, in this case UI events (which, in turn, are supplied by the OS) In fact, there are many things running in parallel to the JS engine, for example, for example thread (which) are managing network connections (and the amount of AJAX events).
No comments:
Post a Comment