title: How to allow Web Workers to receive new data while it still performing computation?
body: <p>I want to sort an array, using Web Workers. But this array might receive new values over time, while the worker is still performing the sort function.</p>
  
  <p>So my question is, how can I "stop" the sorting computation on the worker after receiving the new item, so it can perform the sort on the array with that item, while still keeping the sorting that was already made?</p>
  
  <p>Example:</p>
  
  <pre class="lang-js prettyprint-override"><code>let worker = new Worker('worker.js');
  let list = [10,1,5,2,14,3];
  worker.postMessage({ list });
  setInterval(() =&gt; worker.postMessage({ num: SOME_RANDOM_NUM, list }), 100);
  
  worker.onmessage = event =&gt; {
    list = event.data.list;
  }
  </code></pre>
  
  <p>So lets say that, I've passed 50, the worker made some progress in the sorting before that and now I have something like this:
  <code>[1, 2, 3, 10, 5, 14, 50]</code>. Which means the sorting stopped at index <code>3</code>. So I pass this <code>new</code> array back to the worker, so it can continue the sorting from position <code>3</code>.</p>
  
  <p>How can I accomplish that, since there is no way to pause/resume a web worker? </p>