Class: Qwirk::PublishHandle::WorkerResponse
- Inherits:
-
Object
- Object
- Qwirk::PublishHandle::WorkerResponse
- Defined in:
- lib/qwirk/publish_handle.rb
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#start ⇒ Object
readonly
Returns the value of attribute start.
Instance Method Summary collapse
- #done? ⇒ Boolean
-
#initialize(start) ⇒ WorkerResponse
constructor
A new instance of WorkerResponse.
- #make_exception_call(name, e) ⇒ Object
- #make_message_call(name, obj) ⇒ Object
- #make_timeout_calls ⇒ Object
-
#msec_delta ⇒ Object
Msecs since publish.
- #on_message(*names, &block) ⇒ Object
- #on_remote_exception(*names, &block) ⇒ Object
- #on_timeout(*names, &block) ⇒ Object
Constructor Details
#initialize(start) ⇒ WorkerResponse
Returns a new instance of WorkerResponse.
110 111 112 113 114 115 116 117 118 |
# File 'lib/qwirk/publish_handle.rb', line 110 def initialize(start) @start = start @message_hash = {} @timeout_hash = {} @exception_hash = {} @default_timeout_block = nil @default_exception_block = nil @done_array = [] end |
Instance Attribute Details
#name ⇒ Object (readonly)
Returns the value of attribute name.
108 109 110 |
# File 'lib/qwirk/publish_handle.rb', line 108 def name @name end |
#start ⇒ Object (readonly)
Returns the value of attribute start.
108 109 110 |
# File 'lib/qwirk/publish_handle.rb', line 108 def start @start end |
Instance Method Details
#done? ⇒ Boolean
155 156 157 |
# File 'lib/qwirk/publish_handle.rb', line 155 def done? (@message_hash.keys - @done_array).empty? end |
#make_exception_call(name, e) ⇒ Object
169 170 171 172 173 174 175 176 177 178 |
# File 'lib/qwirk/publish_handle.rb', line 169 def make_exception_call(name, e) @name = name block = @exception_hash[name] || @default_exception_block if block block.call(e) @done_array << name else raise e end end |
#make_message_call(name, obj) ⇒ Object
147 148 149 150 151 152 153 |
# File 'lib/qwirk/publish_handle.rb', line 147 def (name, obj) # Give the client access to the name @name = name block = @message_hash[name] block.call(obj) if block @done_array << name end |
#make_timeout_calls ⇒ Object
159 160 161 162 163 164 165 166 167 |
# File 'lib/qwirk/publish_handle.rb', line 159 def make_timeout_calls @timeouts = @message_hash.keys - @done_array @timeouts.each do |name| # Give the client access to the name @name = name block = @timeout_hash[name] || @default_timeout_block block.call if block end end |
#msec_delta ⇒ Object
Msecs since publish
121 122 123 |
# File 'lib/qwirk/publish_handle.rb', line 121 def msec_delta (Time.now - @start) * 1000 end |
#on_message(*names, &block) ⇒ Object
125 126 127 128 |
# File 'lib/qwirk/publish_handle.rb', line 125 def (*names, &block) raise 'Must explicitly define all message handlers so we know that we\'re done' if names.empty? names.each {|name| @message_hash[name] = block} end |
#on_remote_exception(*names, &block) ⇒ Object
138 139 140 141 142 143 144 145 |
# File 'lib/qwirk/publish_handle.rb', line 138 def on_remote_exception(*names, &block) if names.empty? @default_exception_block = block else names.each {|name| @exception_hash[name] = block} end @remote_exception_block = block end |
#on_timeout(*names, &block) ⇒ Object
130 131 132 133 134 135 136 |
# File 'lib/qwirk/publish_handle.rb', line 130 def on_timeout(*names, &block) if names.empty? @default_timeout_block = block else names.each {|name| @timeout_hash[name] = block} end end |