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

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

Instance Method Summary collapse

Instance Method Details

#stream(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.



146
147
148
149
150
151
152
153
154
155
156
157
158
159
# 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