How to run javascript function in web browser only when is not proccesing that function

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.

I tried to set a flag for running (or not running) that function:

if (!is_calculating)
    is_calculating = true;

my_function(); // do heavy stuff

is_calculating = false;

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 // do heavy stuff

Can I do something for this behavior? I’d like to jump function execution if a flag is set.

Source: cross-browser

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.