Class: Kibosh::Response

Inherits:
Object
  • Object
show all
Includes:
Mixin
Defined in:
lib/kibosh/response.rb

Defined Under Namespace

Modules: Mixin

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Mixin

#body, #body=, #headers, #rack, #status, #status=, #xml

Constructor Details

#initialize(async_callback, close_callback) ⇒ Response

Returns a new instance of Response.



79
80
81
82
83
84
85
86
# File 'lib/kibosh/response.rb', line 79

def initialize async_callback, close_callback
  raise "hell" if !Method === async_callback
  @callback = async_callback
  @closed = close_callback
  @callback.receiver.comm_inactivity_timeout = 0
  @fired = @deferred = false
  @created_at = Time.now
end

Instance Attribute Details

#created_atObject (readonly)

Returns the value of attribute created_at.



88
89
90
# File 'lib/kibosh/response.rb', line 88

def created_at
  @created_at
end

#defer_firedObject

Returns the value of attribute defer_fired.



89
90
91
# File 'lib/kibosh/response.rb', line 89

def defer_fired
  @defer_fired
end

#deferredObject

Returns the value of attribute deferred.



89
90
91
# File 'lib/kibosh/response.rb', line 89

def deferred
  @deferred
end

#deliver_firedObject

Returns the value of attribute deliver_fired.



89
90
91
# File 'lib/kibosh/response.rb', line 89

def deliver_fired
  @deliver_fired
end

#deliveredObject

Returns the value of attribute delivered.



89
90
91
# File 'lib/kibosh/response.rb', line 89

def delivered
  @delivered
end

#sessionObject

Returns the value of attribute session.



68
69
70
# File 'lib/kibosh/response.rb', line 68

def session
  @session
end

#streamObject (readonly)

Returns the value of attribute stream.



68
69
70
# File 'lib/kibosh/response.rb', line 68

def stream
  @stream
end

Instance Method Details

#_cancel!Object



102
103
104
105
106
107
108
109
# File 'lib/kibosh/response.rb', line 102

def _cancel!
  raise "hell" if delivered || !deferred
  self.deferred = false
  @callback.call nil
  self.delivered = true
  @closed = nil
  @callback = nil
end

#_deliverObject



111
112
113
114
115
116
# File 'lib/kibosh/response.rb', line 111

def _deliver
  raise "hell" if delivered || !deferred
  @closed.cancel_callback @close_block
  self.deferred = false
  @callback.call rack
end

#deferObject



91
92
93
94
95
96
# File 'lib/kibosh/response.rb', line 91

def defer
  body = @body
  @body = nil
  @session.defer self
  body
end

#on_close(&block) ⇒ Object



98
99
100
# File 'lib/kibosh/response.rb', line 98

def on_close &block
  @closed.callback &(@close_block = block)
end