class Roda::RodaPlugins::Streaming::AsyncStream

  1. lib/roda/plugins/streaming.rb
Superclass: Object

Class of the response body if you use stream with :async set to true. Uses a separate thread that pushes streaming results to a queue, so that data can be streamed to clients while it is being prepared by the application.


Public Class

  1. new

Public Instance

  1. close
  2. each

Included modules

  1. Enumerable

Public Class methods

new(opts=OPTS, &block)

Handle streaming options, see Streaming for details.

[show source]
    # File lib/roda/plugins/streaming.rb
100 def initialize(opts=OPTS, &block)
101   @stream =, &block)
102   @queue = opts[:queue] || # have some default backpressure
103   @thread = { enqueue_chunks }
104 end

Public Instance methods


Stop streaming.

[show source]
    # File lib/roda/plugins/streaming.rb
113 def close
114   @queue.close # terminate the producer thread
115   @stream.close
116 end

Continue streaming data until the stream is finished.

[show source]
    # File lib/roda/plugins/streaming.rb
107 def each(&out)
108   dequeue_chunks(&out)
109   @thread.join
110 end