class Serf::Client::Callbacks

Public Class Methods

new() click to toggle source
# File lib/serf/client/callbacks.rb, line 9
def initialize
  @callbacks = Hash.new { |h,k| h[k] = [] }
  async.process
end

Public Instance Methods

add(id, cb) click to toggle source
# 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) click to toggle source
# File lib/serf/client/callbacks.rb, line 31
def perform_callback resp, cb
  debug 'callbacks#perform_callback'
  r = cb.call resp
  r
end
process() click to toggle source
# 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