Skip to content

Comment on Automatic Flushing: The Rails 3.1 Planparent

Comments

In Rack you need to return a body which responds to #each (which yields strings); it doesn't need to return the body all at once:

    class Dummy
      def initialize(controller)
        @controller = controller
      end
      
      def each
        @controller.render.each { |part| yield part }
      end
    end
    
    @body = Dummy.new(self)

Aaaah, and the work is done within #each and not within #call. I see. The only issue is if you have a middleware that modifies the output, because unless you're careful and/or you're doing something extremely minor near the start of the page, it'll all be processed in the middleware rather than the server. So the server still gets it all in one piece, and so does the client.

AboutSource Built by g1lg1l

Hackerly is an independent reader for Hacker News, built on the public HN API. Not affiliated with Y Combinator.