Module: Roda::RodaPlugins::Streaming::InstanceMethods

Defined in:
lib/roda/plugins/streaming.rb

Instance Method Summary collapse

Instance Method Details

#stream(opts = OPTS, &block) ⇒ Object

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



148
149
150
151
152
153
154
155
156
157
158
159
160
# File 'lib/roda/plugins/streaming.rb', line 148

def stream(opts=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

  throw :halt, @_response.finish_with_body(Stream.new(opts, &block))
end