class Sidekiq::Hierarchy::CallbackRegistry

Public Class Methods

new() click to toggle source
Calls superclass method
# File lib/sidekiq/hierarchy/callback_registry.rb, line 8
def initialize
  @callbacks = {}
  super
end

Public Instance Methods

publish(event, *args) click to toggle source

Call listeners for a given event one by one. Note that no method signature contracts are enforced.

# File lib/sidekiq/hierarchy/callback_registry.rb, line 26
def publish(event, *args)
  if to_notify = @callbacks[event]
    to_notify.each { |callback| callback.call(*args) rescue nil }
  end
end
subscribe(event, callback) click to toggle source

Thread-safe to prevent clobbering, though this should probably never be called outside initialization anyway. callback is a proc/lambda that implements call

# File lib/sidekiq/hierarchy/callback_registry.rb, line 16
def subscribe(event, callback)
  synchronize do
    @callbacks[event] ||= []
    @callbacks[event] << callback
  end
  self
end