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.

Methods

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 = Stream.new(opts, &block)
102   @queue = opts[:queue] || SizedQueue.new(10) # have some default backpressure
103   @thread = Thread.new { enqueue_chunks }
104 end

Public Instance methods

close()

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
each(&out)

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