title: Dart/Flutter batching of a forEach() loop?
body: <p>I have the following code to make calls to an API to get my data and then parse the results. It's my understanding that "async" on the forEach loop is NOT blocking, hence my use of an input bool to set if I want these to be blocking calls or not.</p>
  
  <p>My issue now is that I'm hitting a "socket: too many open files" error on some of my calls presumably because I've hit a limit in flutter for too many things waiting on the API http responses (let me know if you need more details of the "tx" functions)</p>
  
  <p><strong>So my question is this.  Is there a quick way to throttle the non-blocking "forEach" loop below, and maybe do an await on future.Delayed(Duration(milliseconds:250)) say for every 5th time through the loop?</strong>  </p>
  
  <p>Of course if I just count and await the async call in the below code I think that the forEach loop will keep right on going through the rest.  </p>
  
  <p>Do I have to make a temporary list of all the entries and do them in non blocking batches?  </p>
  
  <pre><code>    if (makeBlocking) {
        for (var r in _commissionData[gwSerial].rooms.entries) {
          Map&lt;String, dynamic&gt; res = await _getSetupRoomDevicesApi.tx(
              _token, _clientId, gwSerialString, r.value.id);
          Map&lt;String, dynamic&gt; res2 = await _listCommissionAssociations.tx(
              _token, _clientId, gwSerialString, r.value.id);
          processCommissionData(r.value, res, res2);
        }
      } else {
        if (_commissionData != null) {
          _commissionData[gwSerial]?.rooms?.forEach((roomId, r) async {
            Map&lt;String, dynamic&gt; res = await _getSetupRoomDevicesApi.tx(
                _token, _clientId, gwSerialString, r.id);
            Map&lt;String, dynamic&gt; res2 = await _listCommissionAssociations.tx(
                _token, _clientId, gwSerialString, r.id);
            processCommissionData(r, res, res2);
          });
        }
      }
  </code></pre>