Class: Thin::AsyncResponse
- Inherits:
-
Object
- Object
- Thin::AsyncResponse
- Includes:
- Rack::Response::Helpers
- Defined in:
- lib/message_bus/rack/thin_ext.rb
Overview
Response which 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.
49 50 51 52 53 54 55 |
# File 'lib/message_bus/rack/thin_ext.rb', line 49 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.
46 47 48 |
# File 'lib/message_bus/rack/thin_ext.rb', line 46 def callback @callback end |
#closed ⇒ Object (readonly)
Returns the value of attribute closed.
46 47 48 |
# File 'lib/message_bus/rack/thin_ext.rb', line 46 def closed @closed end |
#headers ⇒ Object (readonly)
Returns the value of attribute headers.
46 47 48 |
# File 'lib/message_bus/rack/thin_ext.rb', line 46 def headers @headers end |
#status ⇒ Object
Returns the value of attribute status.
47 48 49 |
# File 'lib/message_bus/rack/thin_ext.rb', line 47 def status @status end |
Instance Method Details
#done ⇒ Object
Tell Thin the response is complete and the connection can be closed.
71 72 73 74 75 |
# File 'lib/message_bus/rack/thin_ext.rb', line 71 def done @closed = true send_headers ::EM.next_tick { @body.succeed } end |
#send_headers ⇒ Object
57 58 59 60 61 62 |
# File 'lib/message_bus/rack/thin_ext.rb', line 57 def send_headers return if @headers_sent @callback.call [@status, @headers, @body] @headers_sent = true end |
#write(body) ⇒ Object Also known as: <<
64 65 66 67 |
# File 'lib/message_bus/rack/thin_ext.rb', line 64 def write(body) send_headers @body.call(body.respond_to?(:each) ? body : [body]) end |