Sha256: 4efd4ae3eced8641a8b3b6fcd048d29657bc533230340dba901bc11975b96785

Contents?: true

Size: 759 Bytes

Versions: 6

Compression:

Stored size: 759 Bytes

Contents

require 'nitro/render'

module Nitro

module Render

  # Enable streaming mode for the current HTTP Response.
  # You can optionally provide an existing IO object for 
  # streaming.
  #--
  # This code is considered a hack fix. But it still is useful 
  # so for the moment it stays in the distribution.
  #++
  
  def stream(io = nil)
    if io
      # Reuse an existing IO if it exists.
      @context.out = io
    else  
      r, w = IO.pipe
      
      @context.out = r
      @out = w
      r.sync = true    
      w.class.send(:define_method, :empty?) { false }
  
      Thread.new do 
        begin
          yield
        ensure
    w.close
        end
      end
    end
  end
  
end

end

# * Guillaume Pierronnet <guillaume.pierronnet@laposte.net>

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
nitro-0.41.0 lib/nitro/cgi/stream.rb
nitro-0.28.0 lib/nitro/cgi/stream.rb
nitro-0.29.0 lib/nitro/cgi/stream.rb
nitro-0.30.0 lib/nitro/cgi/stream.rb
nitro-0.31.0 lib/nitro/cgi/stream.rb
nitro-0.40.0 lib/nitro/cgi/stream.rb