Class: Qwirk::PublishHandle::WorkerResponse

Inherits:
Object
  • Object
show all
Defined in:
lib/qwirk/publish_handle.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(start) ⇒ WorkerResponse

Returns a new instance of WorkerResponse.



111
112
113
114
115
116
117
118
119
120
# File 'lib/qwirk/publish_handle.rb', line 111

def initialize(start)
  @start                   = start
  @message_hash            = {}
  @timeout_hash            = {}
  @exception_hash          = {}
  @default_message_block   = nil
  @default_timeout_block   = nil
  @default_exception_block = nil
  @done_array              = []
end

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



109
110
111
# File 'lib/qwirk/publish_handle.rb', line 109

def name
  @name
end

#startObject (readonly)

Returns the value of attribute start.



109
110
111
# File 'lib/qwirk/publish_handle.rb', line 109

def start
  @start
end

Instance Method Details

#done?Boolean

Returns:

  • (Boolean)


160
161
162
# File 'lib/qwirk/publish_handle.rb', line 160

def done?
  !@default_message_block && (@message_hash.keys - @done_array).empty?
end

#make_exception_call(name, e) ⇒ Object



174
175
176
177
178
179
180
181
182
183
# File 'lib/qwirk/publish_handle.rb', line 174

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



152
153
154
155
156
157
158
# File 'lib/qwirk/publish_handle.rb', line 152

def make_message_call(name, obj)
  # Give the client access to the name
  @name = name
  block = @message_hash[name] || @default_message_block
  block.call(obj) if block
  @done_array << name
end

#make_timeout_callsObject



164
165
166
167
168
169
170
171
172
# File 'lib/qwirk/publish_handle.rb', line 164

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_deltaObject

Msecs since publish



123
124
125
# File 'lib/qwirk/publish_handle.rb', line 123

def msec_delta
  (Time.now - @start) * 1000
end

#on_message(*names, &block) ⇒ Object



127
128
129
130
131
132
133
# File 'lib/qwirk/publish_handle.rb', line 127

def on_message(*names, &block)
  if names.empty?
    @default_message_block = block
  else
    names.each {|name| @message_hash[name] = block}
  end
end

#on_remote_exception(*names, &block) ⇒ Object



143
144
145
146
147
148
149
150
# File 'lib/qwirk/publish_handle.rb', line 143

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



135
136
137
138
139
140
141
# File 'lib/qwirk/publish_handle.rb', line 135

def on_timeout(*names, &block)
  if names.empty?
    @default_timeout_block = block
  else
    names.each {|name| @timeout_hash[name] = block}
  end
end