Module: Roda::RodaPlugins::Streaming::InstanceMethods
- Defined in:
- lib/roda/plugins/streaming.rb
Instance Method Summary collapse
-
#handle_stream_error(e, out) ⇒ Object
Handle exceptions raised while streaming when using :loop.
-
#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.
Instance Method Details
#handle_stream_error(e, out) ⇒ Object
Handle exceptions raised while streaming when using :loop
194 195 196 |
# File 'lib/roda/plugins/streaming.rb', line 194 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.
175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 |
# File 'lib/roda/plugins/streaming.rb', line 175 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? 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 |