javascript stop an infinite loop
===

I have a function that might become an infinite loop if several conditions are met. Untrusted users set these conditions so for the purpose of this question please assume the infinite loop is unfixable.

Still I need a way to stop the infinite loop.

Here is some sample code for what i'm trying to do:

    var infiniteloop = false;
    var condition = true
    function loop () {
      while (condition) {
        console.log('hi')
        if (infiniteloop) {
          condition = false
          console.log('oh last one')
        }
      }
    }
    
    loop()

So a few questions based on what I'm trying to do.

 1. If the `infiniteloop` variable is set to true, the loop will stop right?
 2. How do I detect the infinite loop? Something that checks every 3 seconds would be good.
 3. The `infiniteloop` variable cannot be changed while it's looping if it's on the same process. I have to store the variable in a different process?
 4. Whatever detects the infinite loop needs to live in a different process? Ideally same process would be nice but whatever works?


Thanks for your help.