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

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

Instance Method Summary collapse

Instance Method Details

#handle_stream_error(e, out) ⇒ Object

Handle exceptions raised while streaming when using :loop



112
113
114
# File 'lib/roda/plugins/streaming.rb', line 112

def handle_stream_error(e, out)
  raise e
end

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



95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
# File 'lib/roda/plugins/streaming.rb', line 95

def stream(opts=OPTS, &block)
  if opts[:loop]
    block = proc do |out|
      until out.closed?
        begin
          yield(out)
        rescue => e
          handle_stream_error(e, out)
        end
      end
    end
  end

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