Class: Serf::Client::Callbacks
- Inherits:
-
Object
- Object
- Serf::Client::Callbacks
- Includes:
- Celluloid, Celluloid::Logger
- Defined in:
- lib/serf/client/callbacks.rb
Instance Method Summary collapse
- #add(id, cb) ⇒ Object
-
#initialize ⇒ Callbacks
constructor
A new instance of Callbacks.
- #perform_callback(resp, cb) ⇒ Object
- #process ⇒ Object
Constructor Details
#initialize ⇒ Callbacks
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 |
#process ⇒ Object
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 |