module Sinatra::Helpers

def stream(keep_open = false)

after the block has been executed.
The close parameter specifies whether Stream#close should be called

the response body have not yet been generated.
Allows to start sending data to the client even though later parts of
def stream(keep_open = false)
  scheduler = env['async.callback'] ? EventMachine : Stream
  current   = @params.dup
  stream = if scheduler == Stream  && keep_open
    Stream.new(scheduler, false) do |out|
      until out.closed?
        with_params(current) { yield(out) }
      end
    end
  else
    Stream.new(scheduler, keep_open) { |out| with_params(current) { yield(out) } }
  end
  body stream
end