Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>If your major concern is not to freeze UI during lengthy javascript processing you developed, you can refactor loop bodies into sequential steps, such that each step call its next by using <code>window.setTimeout</code>. This technique allows the (single) thread to process UI events between each interaction:</p> <pre><code>var pr = function(x) {console.log(x)}; var COUNT=3; // original regular javascript loop for(var i=0; i&lt;COUNT; i++) { var msg = "current index is (" + i + ")"; pr(msg); } // step-by-step sequential calls var body = function(i) { var msg = "non-blocking for: index is (" + i + ")"; pr(msg); } nonBlockingFor(body, 4); </code></pre> <p>The function <code>nonBlockingFor</code> calls the first argument (as a function) the number of times passed as second argument. It's definition follows:</p> <pre><code>// function constructor var nonBlockingFor = (function() { function _run(context) { if(context.idx &gt; context.max) return; context.fnc(context.idx++); window.setTimeout((function(){ _run(context)}), 1); } return (function _start(ufn, uqt, runId) { _run({idx: 0, max: uqt -1, fnc: ufn || (function(){}), runId: runId}); }); })(); </code></pre> <p>Please note that this is a very simplified function and it can be improved to handle other multi-thread related issues -- i.e: waiting for the threads to finish (join). I hope this code helps you. Please let me know if you like this approach to the problem, I could spend some time improving my suggestion, if you like.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload