title: How to properly call an async forEachOf function nested in a waterfall function
body: <p>I am using the async library in express js and have a problem with using two of the methods properly with callbacks. The variable result3 at the very end of the waterfall consoles out perfectly in its scope. However, in the result function where it needs to be sent to the client, it is a blank array. Thanks in advance.</p>
  
  <pre><code>async.waterfall(
    [
      function(callback) {
        someQuery 
        callback(null,result1);
      },
  
      function(result1, callback) {
        someQuery 
        callback(null,result2);
      },
       function(result2, mainCallback) {
         async.forEachOf(result2, function (result, key, callback) {
           request.query(
            `SELECT * FROM tbl WHERE id = ${result.id};`,
            function(err, recordset) {
              result3 = recordset;
              callback();
            }
          );
  
         }, function (err) {
           if (err) console.error(err.message);
  
           mainCallback(null, result3);
         });
      }
    ],
    function(err, result) {
  
     console.log(result3);
      res.send(
        JSON.stringify({
         result3
        })
      );
    }
  );
  </code></pre>