A route may return any object that responds to #each. For servers that
support iterative response generation, the response is sent as it's
iterated over:
class HelloStreamer
def each
yield "Hello"
sleep 5
yield "World!"
end
end
require 'sinatra'
get '/' do
content_type 'text/plain'
Streamer.new
end
Hitting that with curl, you should see "Hello" and then "World" after a delay.
This works with Mongrel, Unicorn, and Passenger -- maybe with WEBrick.
Thin and anything run under shotgun do not send responses iteratively.
Thanks,
Ryan