Class: Serf::Client::Callbacks

Inherits:
Object
  • Object
show all
Includes:
Celluloid, Celluloid::Logger
Defined in:
lib/serf/client/callbacks.rb

Instance Method Summary collapse

Constructor Details

#initializeCallbacks

Returns a new instance of Callbacks.



9
10
11
12
# File 'lib/serf/client/callbacks.rb', line 9

def initialize
  @callbacks = Hash.new { |h,k| h[k] = [] }
  async.process
end

Instance Method Details

#add(id, cb) ⇒ Object



14
15
16
17
# File 'lib/serf/client/callbacks.rb', line 14

def add id, cb
  debug "callbacks#add with id #{id}"
  @callbacks[id] << cb
end

#perform_callback(resp, cb) ⇒ Object



31
32
33
34
35
# File 'lib/serf/client/callbacks.rb', line 31

def perform_callback resp, cb
  debug 'callbacks#perform_callback'
  r = cb.call resp
  r
end

#processObject



19
20
21
22
23
24
25
26
27
28
29
# File 'lib/serf/client/callbacks.rb', line 19

def process
  loop do
    debug 'callbacks#process!'
    resp = receive
    id = resp.header["Seq"]

    cbs = @callbacks[id]
    cbs.each { |c| async.perform_callback(resp, c) }
    debug 'callbacks#process! done'
  end
end