title: reading from stdin in one second intervals
body: <p>I have two simple scripts, reader and writer:</p>
  
  <p><code>writer.rb</code>:</p>
  
  <pre><code>while true
    puts "hello!"
    $stdout.flush
    sleep 1
  end
  </code></pre>
  
  <p><code>reader.rb</code>:</p>
  
  <pre><code>while true
    puts "I read: #{$stdin.read}!"
    sleep 1
  end
  </code></pre>
  
  <p><code>writer.rb</code> continuously writes to stdout, and <code>reader.rb</code> continuously reads from stdin.</p>
  
  <p>Now if I do this:</p>
  
  <pre><code>ruby writer.rb | ruby reader.rb
  </code></pre>
  
  <p>I would expect this to keep printing</p>
  
  <pre><code>I read: hello!
  I read: hello!
  I read: hello!
  </code></pre>
  
  <p>At one second intervals. But it just blocks without printing anything. How do I get it to print? I thought <code>writer.rb</code> was caching the output so I added <code>$stdout.flush</code>, but that didn't get me anywhere.</p>