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



106
107
108
# File 'lib/roda/plugins/streaming.rb', line 106

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.



89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
# File 'lib/roda/plugins/streaming.rb', line 89

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