title: Nodejs - read line by line from file, perform async action for each line and resume
body: <p>I'm trying to read a file line by line, perform some action that has a callback and when the function finishes to resume line reading. For example:</p>
  
  <pre><code>var fs = require('fs');
  var readline = require('readline');
  var stream = require('stream');
  var instream = fs.createReadStream('./phrases.txt');
  var outstream = new stream;
  var rl = readline.createInterface(instream, outstream);
  rl.on('line', function (line) {
    rl.pause();
    setTimeout(function () {
      console.log('resuming');
      rl.resume();
    }, 2000);
  });
  </code></pre>
  
  <p>I was under the impression the example above should basically read a line, wait for 2 seconds, <code>console.log</code> and then continue to the next line. What really happens is that it waits for the first 2 seconds and then spews out lots of <code>console.log</code></p>