module Roda::RodaPlugins::Streaming::InstanceMethods

  1. lib/roda/plugins/streaming.rb

Methods

Public Instance

  1. handle_stream_error
  2. stream

Public Instance methods

handle_stream_error(e, out)

Handle exceptions raised while streaming when using :loop

[show source]
    # File lib/roda/plugins/streaming.rb
162 def handle_stream_error(e, out)
163   raise e
164 end
stream(opts=OPTS, &block)

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

[show source]
    # File lib/roda/plugins/streaming.rb
143 def stream(opts=OPTS, &block)
144   if opts[:loop]
145     block = proc do |out|
146       until out.closed?
147         begin
148           yield(out)
149         rescue => e
150           handle_stream_error(e, out)
151         end
152       end
153     end
154   end
155 
156   stream_class = (opts[:async] && RUBY_VERSION >= '2.3') ? AsyncStream : Stream
157 
158   throw :halt, @_response.finish_with_body(stream_class.new(opts, &block))
159 end