title: Can I stop the execution of a function from outside that function?
body: <p>I have this code:</p>
  
  <pre><code>function toStop(){
    while(true){}
  }
  toStop();
  </code></pre>
  
  <p>Now, how can I stop this? Or how can I kill the current thread if this function call is somewhere in the <code>setInterval</code> running thread? Example:</p>
  
  <pre><code>var id = setInterval(function(){
    toStop();
  }, 1000);
  
  //stop thread/timer with id here.
  </code></pre>
  
  <p><code>clearInterval</code> doesn't work because it waits until the function call ends.</p>
  
  <p>Thanks!</p>