Skip to content

Commit

Permalink
Making the API for the balancing queue more symmetric with `Callbacks…
Browse files Browse the repository at this point in the history
….on_select` for easier customizing of behavior
  • Loading branch information
karmi committed Nov 13, 2010
1 parent a6bf93e commit 44fb174
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions examples/balancing.rb
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,7 @@ def self.select(strategy = :balanced)
raise ArgumentError, "Unknown strategy: #{@strategy}"
end

puts "---> Selecting #{backend}" if STDOUT.tty?
backend.increment_counter if Backend.strategy == :balanced

Callbacks.on_select.call(backend)
yield backend if block_given?
backend
end
Expand Down Expand Up @@ -102,6 +100,13 @@ module Callbacks
include ANSI::Code
extend self

def on_select
lambda do |backend|
puts black_on_white { 'on_select'.ljust(12) } + " #{backend.inspect}"
backend.increment_counter if Backend.strategy == :balanced
end
end

def on_connect
lambda do |backend|
puts black_on_magenta { 'on_connect'.ljust(12) } + ' ' + bold { backend }
Expand Down

0 comments on commit 44fb174

Please sign in to comment.