Created
May 27, 2010 17:46
-
-
Save qoobaa/416100 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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