title: Wait until every process finishes
body: <p>I am working on a Javascript simulator that runs in a web browser. It has a main loop:</p>
  
  <pre><code>do {
      updateVisualization(simulator);
      simulator.doStep();
  } while (!reachedGoal(simulator));
  </code></pre>
  
  <p>And for every iteration, I need to run several workers that must be concurrently executed:</p>
  
  <pre><code>doStep = function() {
      ...
      for (every agent in the simulation) {
          var worker = new Worker('worker.js');
          worker.onmessage = function(event) {
              ...
          }
          worker.postMessage(...);
      }
  
      // Here is the problem
  }
  </code></pre>
  
  <p>My question is: how could I wait for every worker to finish?</p>