Module: Roda::RodaPlugins::Streaming

Defined in:


The streaming plugin adds support for streaming responses from roda using the stream method:

plugin :streaming

route do |r|
  stream do |out|
    ['a', 'b', 'c'].each{|v| out << v; sleep 1}

In order for streaming to work, any webservers used in front of the roda app must not buffer responses.

The stream method takes the following options:


A callback proc to call when the connection is closed.


Whether to call the stream block continuously until the connection is closed.


Whether to call the stream block in a separate thread (default: false). Only supported on Ruby 2.3+.


A queue object to use for asynchronous streaming (default: ‘`).

If the :loop option is used, you can override the handle_stream_error method to change how exceptions are handled during streaming. This method is passed the exception and the stream. By default, this method just reraises the exception, but you can choose to output the an error message to the stream, before raising:

def handle_stream_error(e, out)
  out << 'ERROR!'
  raise e

Ignore errors completely while streaming:

def handle_stream_error(e, out)

or handle the errors in some other way.

Defined Under Namespace

Modules: InstanceMethods Classes: AsyncStream, Stream