class ActionController::Live::Buffer
:nodoc:
def abort
anything that's being written.
disconnected; the reading thread is no longer interested in
Inform the producer/writing thread that the client has
def abort synchronize do @aborted = true @buf.clear end end
def build_queue(queue_size)
def build_queue(queue_size) queue_size ? SizedQueue.new(queue_size) : Queue.new end
def call_on_error
def call_on_error @error_callback.call end
def close
uses this to notify us that it's finished supplying content.
Write a 'close' event to the buffer; the producer/writing thread
def close synchronize do super @buf.push nil @cv.broadcast end end
def connected?
The result of calling `write` when this is `false` is determined
Is the client still connected and waiting for content?
def connected? !@aborted end
def each_chunk(&block)
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
def initialize(response)
def initialize(response) super(response, build_queue(self.class.queue_size)) @error_callback = lambda { true } @cv = new_cond @aborted = false @ignore_disconnect = false end
def on_error(&block)
def on_error(&block) @error_callback = block end
def write(string)
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
def writeln(string)
def writeln(string) write string.end_with?("\n") ? string : "#{string}\n" end