title: Implementing recursion function inside async.series with callbacks
body: <p>I am stuck with a recursive function which fetches data from dynamodb with "ExclusiveStartKey" and its inside of async.series. How to structure the code inside async.series for the callbacks</p>
  
  <pre><code>var finalArray =  []
  
  function scanQuery(params, callback) {
  
      docClient.scan(params, (err, data) =&gt; {
          if (err) {
              callback(err);
          } else {
              if (typeof data.LastEvaluatedKey != "undefined") {
                 params.ExclusiveStartKey = data.LastEvaluatedKey;
                 scanQuery(params,() =&gt; {
                  callback();
                 })
              }
              else {
  
                  finalArray.push(data.Items);
  
                  callback(finalArray);
              }
          }
      })
  }
  </code></pre>
  
  <pre><code>   async.series(
      [
      function (callback) {
          var params = {
              TableName: "demo",
              ProjectionExpression: "#id, #name, #created_date",
              ExpressionAttributeNames: {
                  "#id": "id",
                  "#name": "name",
                  "#created_date": "created_date"
              }
          };
          console.log("Scanning Cars table.");
  
          scanQuery(params, (err, response) =&gt; {
              if (err) callback(err)
              // console.log(response);
              callback(null,response)
          })
  
  
      },
      function (callback) {
          // do some more stuff ...
          callback(null, 'tree');
      }
  ],
  // optional callback
  function (err, results) {
      console.log(err);
      if (!err) {
          // console.log(results);
          // console.log(finalArray);
          callback(results);
      } else {
          callback("test");
      }
  });
  }
  </code></pre>
  
  <p>Here I would like to get all the results in single call from dynamoDb. FinalArray should contain all the entries at last. So how to modify scanQuery function with callbacks integrating with async.series</p>