Sha256: 2b6fb23a9ccb81d840cac9fca61eba856dc1e713e64bfdf5737d5f9a4cd80c7e
Contents?: true
Size: 826 Bytes
Versions: 9
Compression:
Stored size: 826 Bytes
Contents
require 'mutex_m' module Sidekiq module Hierarchy class CallbackRegistry include Mutex_m def initialize @callbacks = {} super end # Thread-safe to prevent clobbering, though this should # probably never be called outside initialization anyway. # callback is a proc/lambda that implements #call def subscribe(event, callback) synchronize do @callbacks[event] ||= [] @callbacks[event] << callback end self end # Call listeners for a given event one by one. # Note that no method signature contracts are enforced. def publish(event, *args) if to_notify = @callbacks[event] to_notify.each { |callback| callback.call(*args) rescue nil } end end end end end
Version data entries
9 entries across 9 versions & 1 rubygems