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 = RodaPlugins::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
199 200 201 |
# File 'lib/roda/plugins/streaming.rb', line 199 def handle_stream_error(e, out) raise e end |
#stream(opts = RodaPlugins::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.
177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 |
# File 'lib/roda/plugins/streaming.rb', line 177 def stream(opts=RodaPlugins::OPTS, &block) if !opts.has_key?(:scheduler) && env['async.callback'] RodaPlugins.warn 'The automatic support for EventMachine in the streaming plugin is deprecated and will be removed in Roda 3.' opts = opts.merge(:scheduler=>EventMachine) end 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 |