title: How to run javascript function in web browser only when is not proccesing that function
body: <p>One of my javascript function is processing millions of data and it is called ~1 time every second from a hardware event. Then the web browser is idle in that function processing.</p>
  
  <p>I tried to set a flag for running (or not running) that function:</p>
  
  <pre><code>if (!is_calculating)
      is_calculating = true;
  else
      return;
  
  
  my_function(); // do heavy stuff
  
  
  is_calculating = false;
  </code></pre>
  
  <p>but it's not working, because it is entering into the code and the web browser enter in an idle status until is finishing. When it is returning, the flag is always OK, because it finished the <em>// do heavy stuff</em></p>
  
  <p>Can I do something for this behavior? I'd like to jump function execution if a flag is set. </p>