title: Knowing EOF when using node.js and lazy
body: <p>I have a routine written in CoffeeScript, running in node.js that reads lines from a Jade-file. It looks like this:</p>
  
  <pre><code>each_line = (file, callback) -&gt;
    last_line = null
  
    lazy = Lazy(fs.createReadStream(file)).lines.map(String).filter (line) -&gt; 
      not (
        # Filter the not interesting rows in the top of the file
        /^html$/i.test(line) or 
        /^\s+body$/i.test(line) or 
        /^\s+\/\/\s+Generator.*$/i.test(line)
        )
  
    lazy.forEach (line) -&gt;
      # We only emit those lines that are whole lines, multilines will become joined
      if /^\t/g.test(line)
        last_line += line.replace(/\t/g, '').replace(/(\r\n|\n|\r)/gm," ")
      else
        callback(last_line) if last_line
        last_line = line.replace(/(\r\n|\n|\r)/gm," ")
  </code></pre>
  
  <p>Since all this runs async, I need to know EOF so that I can perform operations after the whole iteration is done. Does anyone have any suggestions?</p>