class Wisper::GlobalListeners
Public Class Methods
clear()
click to toggle source
# File lib/wisper/global_listeners.rb, line 64 def self.clear instance.clear end
listeners()
click to toggle source
# File lib/wisper/global_listeners.rb, line 60 def self.listeners instance.listeners end
new()
click to toggle source
# File lib/wisper/global_listeners.rb, line 11 def initialize @registrations = Set.new @mutex = Mutex.new end
registrations()
click to toggle source
# File lib/wisper/global_listeners.rb, line 56 def self.registrations instance.registrations end
subscribe(*listeners)
click to toggle source
# File lib/wisper/global_listeners.rb, line 48 def self.subscribe(*listeners) instance.subscribe(*listeners) end
unsubscribe(*listeners)
click to toggle source
# File lib/wisper/global_listeners.rb, line 52 def self.unsubscribe(*listeners) instance.unsubscribe(*listeners) end
Public Instance Methods
clear()
click to toggle source
# File lib/wisper/global_listeners.rb, line 44 def clear with_mutex { @registrations.clear } end
listeners()
click to toggle source
# File lib/wisper/global_listeners.rb, line 40 def listeners registrations.map(&:listener).freeze end
registrations()
click to toggle source
# File lib/wisper/global_listeners.rb, line 36 def registrations with_mutex { @registrations } end
subscribe(*listeners)
click to toggle source
# File lib/wisper/global_listeners.rb, line 16 def subscribe(*listeners) options = listeners.last.is_a?(Hash) ? listeners.pop : {} with_mutex do listeners.each do |listener| @registrations << ObjectRegistration.new(listener, options) end end self end
unsubscribe(*listeners)
click to toggle source
# File lib/wisper/global_listeners.rb, line 27 def unsubscribe(*listeners) with_mutex do @registrations.delete_if do |registration| listeners.include?(registration.listener) end end self end
Private Instance Methods
with_mutex() { || ... }
click to toggle source
# File lib/wisper/global_listeners.rb, line 70 def with_mutex @mutex.synchronize { yield } end