# Passing a block to Rack::Response#finish # # You can pass a block to #write, which yields self; # calls to #write inside the block will write directly to the # output stream instead of Rack::Response's internal buffer class App def call(env) Rack::Response.new.finish do |resp| resp.write "one\n" sleep 1 resp.write "two\n" sleep 1 resp.write "three\n" end end end run App.new # Run with "rackup" command; use curl to connect: # # > curl localhost:9292 # one # two # three