title: How to pause and resume function execution in javascript
body: <p>I have this function:</p>
  <pre><code>const BFS = (graph, start) =&gt; {
    let queue = []
    queue.push(start)
  
    let visited = []
    visited[start] = true
  
    while (queue.lenght &gt; 0) {
      let node = queue.shift()
      for (var i=1; i&lt;graph[node].length; i++) {
        if (graph[node][i] &amp;&amp; !visited[i]) {
          visited[i] = true
          queue.push(i)
        }
      }
    }
  }
  </code></pre>
  <p>What I want is to have a button that when I press it, It stops the execution of the function, and if I press it again, it resumes the execution from the same place it stopped on.</p>
  <p>Is that possible ? and if so, how to do it ?</p>