title: Parallel Processing the API and Update Table
body: <p>I need to call the API and on successful message there is an update statement which runs to update the staging table. Everything was working fine until the payload size is small .Now when the data is more ,it gives the memory issue. So I need to pass the 100 materials once and call the API. </p>
  
  <p>In the payload header is same and only the MATERIAL array gets expanded based on the user selection in the application.</p>
  
  <p><strong>Current Code Sample:</strong></p>
  
  <pre><code>//Input
      payload = {
                  "KEY"        : "Af5etwe6w21wreS#",
                  "PARENT_KEY" : "Ag51ts22e6wwrtF#",
                  "ACCOUNT_NO" :  "0000445756"
                  "MATERIAL"  :[{"KEY:"CddefwadsseS#","MAT_NO":"100"},
                                {"KEY:"CddefwadsseS#","MAT_NO":"100"},
                                {"KEY:"CddefwadsseS#","MAT_NO":"100"},{},{} ...........{}]
                }
  
   //API Call function and update Staging     
   const sendsimulate = async(req, keys, headers, input) =&gt; {
  
          let response = await simlib({
                  method: "post",
                  url: 'https://utx.cf.apps.com',
                  headers,
                  data: input
              });
  
            await db.runquery('UPDATE STAGING SET MATERIAL_PRICE=b.MATERIAL_PRICE FROM STAGING a,ITEMS b WHERE a.KEY=b.KEY)
  
             }
  
  
  //Call function
  
  alib.sendsimulate(req, keys, headers, payload);
  </code></pre>
  
  <p><strong>Extended Code:</strong></p>
  
  <p>I tried to modify my code to split the material array into 100 and call parallel and once all are successful I will update the staging. 
  But I am not sure how to do it in parallel. Kindly help me</p>
  
  <pre><code>let newarr = []
  for (var i=0,len=payload.length; i&lt;len; i+=100)
  {  
      newarr.push(payload.MATERIAL.slice(i,i+100));
      payload.MATERIAL=newarr;
      alib.sendsimulate(req, keys, headers, payload);
  
  }
   await db.runquery('UPDATE STAGING SET MATERIAL_PRICE=b.MATERIAL_PRICE FROM STAGING a,ITEMS b WHERE a.KEY=b.KEY)
  </code></pre>