What is the best way to limit concurrency when using ES6's Promise.all()? : <p>I have some code that is iterating over a list that was queried out of a database and making an HTTP request for each element in that list.  That list can sometimes be a reasonably large number (in the thousands), and I would like to make sure I am not hitting a web server with thousands of concurrent HTTP requests.</p>

<p>An abbreviated version of this code currently looks something like this...</p>

<pre><code>function getCounts() {
  return users.map(user =&gt; {
    return new Promise(resolve =&gt; {
      remoteServer.getCount(user) // makes an HTTP request
      .then(() =&gt; {
        /* snip */
        resolve();
      });
    });
  });
}

Promise.all(getCounts()).then(() =&gt; { /* snip */});
</code></pre>

<p>This code is running on Node 4.3.2.  To reiterate, can <code>Promise.all</code> be managed so that only a certain number of Promises are in progress at any given time?</p>
