Class: ActionController::Live::Buffer
- Inherits:
-
ActionDispatch::Response::Buffer
- Object
- ActionDispatch::Response::Buffer
- ActionController::Live::Buffer
- Includes:
- MonitorMixin
- Defined in:
- actionpack/lib/action_controller/metal/live.rb
Overview
:nodoc:
Instance Attribute Summary collapse
-
#ignore_disconnect ⇒ Object
Ignore that the client has disconnected.
Instance Method Summary collapse
-
#abort ⇒ Object
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 ⇒ Object
-
#close ⇒ Object
Write a ‘close’ event to the buffer; the producer/writing thread uses this to notify us that it’s finished supplying content.
-
#connected? ⇒ Boolean
Is the client still connected and waiting for content?.
-
#initialize(response) ⇒ Buffer
constructor
A new instance of Buffer.
- #on_error(&block) ⇒ Object
- #write(string) ⇒ Object
Methods inherited from ActionDispatch::Response::Buffer
Constructor Details
#initialize(response) ⇒ Buffer
Returns a new instance of Buffer.
139 140 141 142 143 144 145 |
# File 'actionpack/lib/action_controller/metal/live.rb', line 139 def initialize(response) @error_callback = lambda { true } @cv = new_cond @aborted = false @ignore_disconnect = false super(response, SizedQueue.new(10)) end |
Instance Attribute Details
#ignore_disconnect ⇒ Object
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.
137 138 139 |
# File 'actionpack/lib/action_controller/metal/live.rb', line 137 def ignore_disconnect @ignore_disconnect end |
Instance Method Details
#abort ⇒ Object
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.
184 185 186 187 188 189 |
# File 'actionpack/lib/action_controller/metal/live.rb', line 184 def abort synchronize do @aborted = true @buf.clear end end |
#call_on_error ⇒ Object
203 204 205 |
# File 'actionpack/lib/action_controller/metal/live.rb', line 203 def call_on_error @error_callback.call end |
#close ⇒ Object
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.
171 172 173 174 175 176 177 |
# File 'actionpack/lib/action_controller/metal/live.rb', line 171 def close synchronize do super @buf.push nil @cv.broadcast end end |
#connected? ⇒ Boolean
Is the client still connected and waiting for content?
The result of calling write when this is false is determined by ignore_disconnect.
195 196 197 |
# File 'actionpack/lib/action_controller/metal/live.rb', line 195 def connected? !@aborted end |
#on_error(&block) ⇒ Object
199 200 201 |
# File 'actionpack/lib/action_controller/metal/live.rb', line 199 def on_error(&block) @error_callback = block end |
#write(string) ⇒ Object
147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 |
# File 'actionpack/lib/action_controller/metal/live.rb', line 147 def write(string) unless @response.committed? @response.set_header "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 |