module Roda::RodaPlugins::Streaming::InstanceMethods

Public Instance Methods

stream(opts={}) { |out| ... } click to toggle source

Immediately return a streaming response using the current response status and headers, calling the block to get the streaming response. See Streaming for details.

# File lib/roda/plugins/streaming.rb, line 146
def stream(opts={}, &block)
  opts = opts.merge(:scheduler=>EventMachine) if !opts.has_key?(:scheduler) && env['async.callback']

  if opts[:loop]
    block = proc do |out|
      until out.closed?
        yield(out)
      end
    end
  end

  res = response
  request.halt [res.status || 200, res.headers, Stream.new(opts, &block)]
end