Class: ActionController::Live::Buffer
| Relationships & Source Files | |
| Super Chains via Extension / Inclusion / Inheritance | |
| 
         Class Chain: 
        
       | 
    |
| 
         Instance Chain: 
        
          self,
          MonitorMixin,
           
      ::ActionDispatch::Response::Buffer
         | 
    |
| Inherits: | 
        ActionDispatch::Response::Buffer
        
  | 
    
| Defined in: | actionpack/lib/action_controller/metal/live.rb | 
Constant Summary
::ActionDispatch::Response::Buffer - Inherited
  
Class Attribute Summary
- .queue_size rw
 
Class Method Summary
Instance Attribute Summary
- 
    
      #connected?  ⇒ Boolean 
    
    readonly
    
Is the client still connected and waiting for content?
 - 
    
      #ignore_disconnect  
    
    rw
    
Ignore that the client has disconnected.
 
::ActionDispatch::Response::Buffer - Inherited
Instance Method Summary
- 
    
      #abort  
    
    
Inform the producer/writing thread that the client has disconnected; the reading thread is no longer interested in anything that’s being written.
 - #call_on_error
 - 
    
      #close  
    
    
Write a ‘close’ event to the buffer; the producer/writing thread uses this to notify us that it’s finished supplying content.
 - #on_error(&block)
 - #write(string)
 - 
    
      #writeln(string)  
    
    
Same as #write but automatically include a newline at the end of the string.
 - #build_queue(queue_size) private
 - #each_chunk(&block) private
 
::ActionDispatch::Response::Buffer - Inherited
| #<< | Alias for ActionDispatch::Response::Buffer#write.  | 
    
| #abort, #body, #close, #each, #respond_to?, #to_ary, #write, #each_chunk | |
Constructor Details
    .new(response)  ⇒ Buffer 
  
# File 'actionpack/lib/action_controller/metal/live.rb', line 166
def initialize(response) super(response, build_queue(self.class.queue_size)) @error_callback = lambda { true } @cv = new_cond @aborted = false @ignore_disconnect = false end
Class Attribute Details
.queue_size (rw)
[ GitHub ]# File 'actionpack/lib/action_controller/metal/live.rb', line 155
attr_accessor :queue_size
Instance Attribute Details
    #connected?  ⇒ Boolean  (readonly)
  
Is the client still connected and waiting for content?
The result of calling #write when this is false is determined by #ignore_disconnect.
# File 'actionpack/lib/action_controller/metal/live.rb', line 225
def connected? !@aborted end
#ignore_disconnect (rw)
Ignore that the client has disconnected.
If this value is true, calling #write after the client disconnects will result in the written content being silently discarded. If this value is false (the default), a ClientDisconnected exception will be raised.
# File 'actionpack/lib/action_controller/metal/live.rb', line 164
attr_accessor :ignore_disconnect
Instance Method Details
#abort
Inform the producer/writing thread that the client has disconnected; the reading thread is no longer interested in anything that’s being written.
See also #close.
# File 'actionpack/lib/action_controller/metal/live.rb', line 214
def abort synchronize do @aborted = true @buf.clear end end
#build_queue(queue_size) (private)
[ GitHub ]# File 'actionpack/lib/action_controller/metal/live.rb', line 249
def build_queue(queue_size) queue_size ? SizedQueue.new(queue_size) : Queue.new end
#call_on_error
[ GitHub ]# File 'actionpack/lib/action_controller/metal/live.rb', line 233
def call_on_error @error_callback.call end
#close
Write a ‘close’ event to the buffer; the producer/writing thread uses this to notify us that it’s finished supplying content.
See also #abort.
# File 'actionpack/lib/action_controller/metal/live.rb', line 202
def close synchronize do super @buf.push nil @cv.broadcast end end
#each_chunk(&block) (private)
[ GitHub ]# File 'actionpack/lib/action_controller/metal/live.rb', line 238
def each_chunk(&block) loop do str = nil ActiveSupport::Dependencies.interlock.permit_concurrent_loads do str = @buf.pop end break unless str yield str end end
#on_error(&block)
[ GitHub ]# File 'actionpack/lib/action_controller/metal/live.rb', line 229
def on_error(&block) @error_callback = block end
#write(string)
[ GitHub ]# File 'actionpack/lib/action_controller/metal/live.rb', line 174
def write(string) unless @response.committed? @response.headers["Cache-Control"] ||= "no-cache" @response.delete_header "Content-Length" end super unless connected? @buf.clear unless @ignore_disconnect # Raise ClientDisconnected, which is a RuntimeError (not an IOError), because # that's more appropriate for something beyond the developer's control. raise ClientDisconnected, "client disconnected" end end end
#writeln(string)
Same as #write but automatically include a newline at the end of the string.
# File 'actionpack/lib/action_controller/metal/live.rb', line 194
def writeln(string) write string.end_with?("\n") ? string : "#{string}\n" end