Sha256: c355c638930d241212adfc82739294c819414d40eb60ed2df8a833a45a51c798
Contents?: true
Size: 925 Bytes
Versions: 1
Compression:
Stored size: 925 Bytes
Contents
require 'singleton' module Wisper class GlobalListeners include Singleton attr_reader :mutex private :mutex def initialize @registrations = Set.new @mutex = Mutex.new end def add_listener(listener, options = {}) with_mutex { @registrations << ObjectRegistration.new(listener, options) } self end def registrations with_mutex { @registrations } end def listeners registrations.map(&:listener).freeze end def clear with_mutex { @registrations.clear } end def self.add_listener(listener, options = {}) instance.add_listener(listener, options) end def self.registrations instance.registrations end def self.listeners instance.listeners end def self.clear instance.clear end private def with_mutex mutex.synchronize { yield } end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
wisper-1.1.0 | lib/wisper/global_listeners.rb |