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.



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

#nameObject (readonly)

Returns the value of attribute name.



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

def name
  @name
end

#startObject (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

Returns:

  • (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 make_message_call(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_callsObject



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_deltaObject

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 on_message(*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