title: how to call function in node loop one at a time
body: <p>this block of code process else block first and then if block, for all request at once, i need a code that execute 5  iterations stop for 15 sec. and then again continue from next 5 iterations and so on.</p>
  
  <pre><code>function passotken(token, callback) {
  
  
  async.waterfall([
  function(callback) {
  db.executesql("select top 20 ext_id as EMPNUM ,  data as datae from newtable", function (data, err) {
  
      callback(null, data);
      });
  },
  function(data, callback) {
      var _json_parse = JSON.parse(JSON.stringify(data));
      var rows = data.length;
  
      console.log(rows)
      var cnt = 1;
  
      for (var row = 1; row &lt;= rows; row++) {
  
      logger.info(_json_parse[row-1].EMPNUM);
      //console.log(dateFormat(_json_parse[row].datae));                      
      var req = 'https://pratik.com/ta/rest/v2/companies/|RHV/employees/|' +_json_parse[row-1].EMPNUM + '/timesheets?date=' + dateFormat(_json_parse[row-1].datae, "isoDate");
      //console.log(req);
      var myXMLText = req;
  
      reques.push(myXMLText);
  
      }
     // console.log(reques);
  
      for (var a = 0; a &lt; rows; a++) {
           //CURRENTLY PROCESSING ALL REQUEST IN IF BLOCK AND STOP FOR 15 SEC FOR ONLY FIRST IF CONDITION AFTER THAT ALL IF CONDITION PROCESSING WITHOUT HALT
      if(a%5==0)
      {
          console.log("if");
          //console.log(reques[a]);
  
          //postreq(reques[a],token,sleeped(a));
        /*  setTimeout(function(){sleeped(reques[a],token);;
  
      },15000); */
          sleeped(reques[a],token);
  
  
          //SHOULD PROCESS IF BLOCK ONCE AND STOP FOR 15 SEC
      }
      else
      {
  
          postreqELSE(reques[a],token);
          //SHOULD PROCESS ALL REQUECT IN ELSE BLOCK TILL IF CONDITION ABOVE NOT SATISY
  
      }
  
      }
  
  Promise.all(ps)
  .then((results) =&gt; {
  console.log("results"); // Result of all resolve as an array
  }).catch(err =&gt; console.log("err")); 
  },
  ], function(err, result) {
  if (!err)
      console.log("Successfully completed")
  else console.log(err);
  });
  };
  
  function callback() {
  console.log("completed successfully");
  }
  
  function postreq(request1,token)
  {
  //BLOCK
  
      }
  
      function sleeped(requesarr,token)
      {
      console.log("in sleeping");
      //console.log(requesarr,token)
  
      setTimeout(function(){
          postreq(requesarr,token);
      },15000);}
  
  
      function postreqELSE(request2,token1)
  {
  console.log("in 3RD function");
     //BLOCK2
  
      }
  </code></pre>