Sha256: 4ccc00176471168d24993ae70a978056821bc3c9f39b66511ebbe2ab7c391935

Contents?: true

Size: 808 Bytes

Versions: 1

Compression:

Stored size: 808 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
        rescue Object => ex
          p ex
        ensure
          w.close
        end
      end
    end
  end
  
end

end

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

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
nitro-0.27.0 lib/nitro/cgi/stream.rb