title: How can I stagger http requests?
body: <p>I have an <code>async</code> function in order to make a series of http requests which I would like to be buffered by 1 second in between requests.  I am utilizing <code>async.forEachof</code> and putting the iterator callback function in the callback of the <code>http.request</code> method.  Code is below</p>
  
  <pre><code>const async = require('async');
  const http = require('http');
  let https = require('https');
  let fs = require('fs');
  
  async.forEachOf([0,1,2,3], function(tag, index, cb){
    let options = {
      host: 'www.google.com',
      path: '/',
      method: 'GET',
    };
  
    var waitTill = new Date(new Date().getTime() + 1000);
    while(waitTill &gt; new Date()){}
  
    console.log('POST');
  
    https.request(options, function(res){
      console.log(res.statusCode);
      cb()
    }).end(JSON.stringify({}));
  });
  </code></pre>
  
  <p>I would expect output to be</p>
  
  <p><code>POST</code></p>
  
  <p><code>200</code></p>
  
  <p><code>POST</code></p>
  
  <p><code>200</code></p>
  
  <p>etc...</p>
  
  <p>Instead I get</p>
  
  <p><code>POST</code></p>
  
  <p><code>POST</code></p>
  
  <p><code>POST</code></p>
  
  <p><code>POST</code></p>
  
  <p><code>200</code></p>
  
  <p><code>200</code></p>
  
  <p><code>200</code></p>
  
  <p><code>200</code></p>
  
  <p>So all the requests are firing at the same time, and the iteration is not waiting for the previous function to complete.  I don't understand.</p>