Class: TemplateStreaming::Autoflushing::Middleware::BodyProxy
- Inherits:
-
Object
- Object
- TemplateStreaming::Autoflushing::Middleware::BodyProxy
- Defined in:
- lib/template_streaming/autoflushing.rb
Instance Method Summary collapse
- #each ⇒ Object
-
#initialize(body) ⇒ BodyProxy
constructor
A new instance of BodyProxy.
Constructor Details
#initialize(body) ⇒ BodyProxy
Returns a new instance of BodyProxy.
63 64 65 |
# File 'lib/template_streaming/autoflushing.rb', line 63 def initialize(body) @body = body end |
Instance Method Details
#each ⇒ Object
67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 |
# File 'lib/template_streaming/autoflushing.rb', line 67 def each buffered_chunks = [] autoflush_due_at = Time.now.to_f @body.each do |chunk| buffered_chunks << chunk if Time.now.to_f >= autoflush_due_at yield buffered_chunks.join buffered_chunks.clear autoflush_due_at = Time.now.to_f + TemplateStreaming.autoflush end end unless buffered_chunks.empty? yield buffered_chunks.join end end |