Class: Thin::AsyncResponse
- Inherits:
-
Object
- Object
- Thin::AsyncResponse
- Includes:
- Rack::Response::Helpers
- Defined in:
- lib/message_bus/rack/thin_ext.rb
Overview
Response whos body is sent asynchronously.
Instance Attribute Summary collapse
-
#callback ⇒ Object
readonly
Returns the value of attribute callback.
-
#closed ⇒ Object
readonly
Returns the value of attribute closed.
-
#headers ⇒ Object
readonly
Returns the value of attribute headers.
-
#status ⇒ Object
Returns the value of attribute status.
Instance Method Summary collapse
-
#done ⇒ Object
Tell Thin the response is complete and the connection can be closed.
-
#initialize(env, status = 200, headers = {}) ⇒ AsyncResponse
constructor
A new instance of AsyncResponse.
- #send_headers ⇒ Object
- #write(body) ⇒ Object (also: #<<)
Constructor Details
#initialize(env, status = 200, headers = {}) ⇒ AsyncResponse
Returns a new instance of AsyncResponse.
44 45 46 47 48 49 50 |
# File 'lib/message_bus/rack/thin_ext.rb', line 44 def initialize(env, status = 200, headers = {}) @callback = env['async.callback'] @body = DeferrableBody.new @status = status @headers = headers @headers_sent = false end |
Instance Attribute Details
#callback ⇒ Object (readonly)
Returns the value of attribute callback.
41 42 43 |
# File 'lib/message_bus/rack/thin_ext.rb', line 41 def callback @callback end |
#closed ⇒ Object (readonly)
Returns the value of attribute closed.
41 42 43 |
# File 'lib/message_bus/rack/thin_ext.rb', line 41 def closed @closed end |
#headers ⇒ Object (readonly)
Returns the value of attribute headers.
41 42 43 |
# File 'lib/message_bus/rack/thin_ext.rb', line 41 def headers @headers end |
#status ⇒ Object
Returns the value of attribute status.
42 43 44 |
# File 'lib/message_bus/rack/thin_ext.rb', line 42 def status @status end |
Instance Method Details
#done ⇒ Object
Tell Thin the response is complete and the connection can be closed.
65 66 67 68 69 |
# File 'lib/message_bus/rack/thin_ext.rb', line 65 def done @closed = true send_headers ::EM.next_tick { @body.succeed } end |
#send_headers ⇒ Object
52 53 54 55 56 |
# File 'lib/message_bus/rack/thin_ext.rb', line 52 def send_headers return if @headers_sent @callback.call [@status, @headers, @body] @headers_sent = true end |
#write(body) ⇒ Object Also known as: <<
58 59 60 61 |
# File 'lib/message_bus/rack/thin_ext.rb', line 58 def write(body) send_headers @body.call(body.respond_to?(:each) ? body : [body]) end |