Class: Thin::AsyncResponse

Inherits:
Object
  • Object
show all
Includes:
Rack::Response::Helpers
Defined in:
lib/message_bus/rack/thin_ext.rb

Overview

Response whos body is sent asynchronously.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(env, status = 200, headers = {}) ⇒ AsyncResponse

Returns a new instance of AsyncResponse.



48
49
50
51
52
53
54
# File 'lib/message_bus/rack/thin_ext.rb', line 48

def initialize(env, status = 200, headers = {})
  @callback = env['async.callback']
  @body = DeferrableBody.new
  @status = status
  @headers = headers
  @headers_sent = false
end

Instance Attribute Details

#callbackObject (readonly)

Returns the value of attribute callback.



45
46
47
# File 'lib/message_bus/rack/thin_ext.rb', line 45

def callback
  @callback
end

#closedObject (readonly)

Returns the value of attribute closed.



45
46
47
# File 'lib/message_bus/rack/thin_ext.rb', line 45

def closed
  @closed
end

#headersObject (readonly)

Returns the value of attribute headers.



45
46
47
# File 'lib/message_bus/rack/thin_ext.rb', line 45

def headers
  @headers
end

#statusObject

Returns the value of attribute status.



46
47
48
# File 'lib/message_bus/rack/thin_ext.rb', line 46

def status
  @status
end

Instance Method Details

#doneObject

Tell Thin the response is complete and the connection can be closed.



70
71
72
73
74
# File 'lib/message_bus/rack/thin_ext.rb', line 70

def done
  @closed = true
  send_headers
  ::EM.next_tick { @body.succeed }
end

#send_headersObject



56
57
58
59
60
61
# File 'lib/message_bus/rack/thin_ext.rb', line 56

def send_headers
  return if @headers_sent

  @callback.call [@status, @headers, @body]
  @headers_sent = true
end

#write(body) ⇒ Object Also known as: <<



63
64
65
66
# File 'lib/message_bus/rack/thin_ext.rb', line 63

def write(body)
  send_headers
  @body.call(body.respond_to?(:each) ? body : [body])
end