by tenderlove · 14y ago · 0 comments
def index
self.response_body = Enumerator.new do |socket|
100.times do
socket << "hello world"
end
end
end
Your API is a little less verbose, I'll give you that, but I don't see why you need Queues and Threads unless the problem actually calls for those things. It still looks like you are writing to a socket either way. headers['X-Accel-Buffering'] = 'no'That's what you do when you yield to the each's block. It's not like the caller calls each multiple times when it wants new data, he calls `each` once and you feed it data via the block it provides.
> Somehow data must be fed to the `each` function
Just as it "must be" fed to the `write` in your examples.
> That's what you do when you yield to the each's block.
No IO object in ruby uses the `each` method for writing.
Rack responses are IO objects, so they use #each to write data out. That's perfectly coherent.
Don't believe me? Let's undefine #each on the metaclass of an IO object and see what happens. Guess what: it still works!