module Roda::RodaPlugins::Chunked::InstanceMethods

def each_chunk

Yield each chunk of the template rendering separately.
def each_chunk
  response.body.each{|s| yield s}
  template, opts = @_each_chunk_args
  # Use a lambda for the flusher, so that a call to flush
  # by a template can result in this method yielding a chunk
  # of the response.
  @_flusher = lambda do
    yield @_out_buf
    @_out_buf = String.new
  end
  if layout_opts  = view_layout_opts(opts)
    @_out_buf = render_template(layout_opts) do
      flush
      run_delayed_blocks
      yield opts[:content] || render_template(template, opts)
      nil
    end
  else
    run_delayed_blocks
    yield view(template, opts)
  end
  flush
rescue => e
  handle_chunk_error(e)
end