Skip to content

Instantly share code, notes, and snippets.

@qoobaa
Created May 27, 2010 17:46
Show Gist options
  • Save qoobaa/416100 to your computer and use it in GitHub Desktop.
Save qoobaa/416100 to your computer and use it in GitHub Desktop.
def read_body # Net::HTTPResponse#read_body
yield "foo"; yield "bar"; yield "baz"
end
class R # A Rack Streaming response
def initialize
@l = lambda do |block|
read_body do |chunk| # Net::HTTPResponse#read_body
sleep(0.5)
block.call(chunk)
end
end
end
def each(&block)
@l.call(block)
end
end
R.new.each do |chunk|
puts chunk # Streaming!
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment