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

Version Path
sidekiq-hierarchy-2.1.0 lib/sidekiq/hierarchy/callback_registry.rb
sidekiq-hierarchy-2.0.1 lib/sidekiq/hierarchy/callback_registry.rb
sidekiq-hierarchy-2.0.0 lib/sidekiq/hierarchy/callback_registry.rb
sidekiq-hierarchy-1.1.0 lib/sidekiq/hierarchy/callback_registry.rb
sidekiq-hierarchy-1.0.0 lib/sidekiq/hierarchy/callback_registry.rb
sidekiq-hierarchy-0.1.4 lib/sidekiq/hierarchy/callback_registry.rb
sidekiq-hierarchy-0.1.3 lib/sidekiq/hierarchy/callback_registry.rb
sidekiq-hierarchy-0.1.2 lib/sidekiq/hierarchy/callback_registry.rb
sidekiq-hierarchy-0.1.1 lib/sidekiq/hierarchy/callback_registry.rb