class Roda::RodaPlugins::Streaming::AsyncStream

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

def close

Stop streaming.
def close
  @queue.close # terminate the producer thread
  @stream.close
end

def dequeue_chunks

Pop each streaming chunk from the queue and yield it.
def dequeue_chunks
  while chunk = @queue.pop
    yield chunk
  end
end

def each(&out)

Continue streaming data until the stream is finished.
def each(&out)
  dequeue_chunks(&out)
  @thread.join
end

def enqueue_chunks

Push each streaming chunk onto the queue.
def enqueue_chunks
  @stream.each do |chunk|
    @queue.push(chunk)
  end
rescue ClosedQueueError
  # connection was closed
ensure
  @queue.close
end

def initialize(opts=OPTS, &block)

Handle streaming options, see Streaming for details.
def initialize(opts=OPTS, &block)
  @stream = Stream.new(opts, &block)
  @queue = opts[:queue] || SizedQueue.new(10) # have some default backpressure
  @thread = Thread.new { enqueue_chunks }
end