Sha256: 6d657a2378f207f4cb6f72ff557939d69a8e074038a47130676109af6f0e9d62
Contents?: true
Size: 1.47 KB
Versions: 25
Compression:
Stored size: 1.47 KB
Contents
class ChannelTasks @@listeners = {} @@channel_listeners = {} # The dispatcher passes its self in def initialize(channel, dispatcher=nil) @channel = channel end def add_listener(channel_name, scope={}) # Track every channel that is listening @@listeners[channel_name] ||= [] @@listeners[channel_name] << @channel # Also keep track of which channel names a channel is listening # on so it can be removed if a channel is closed. @@channel_listeners[@channel] ||= {} @@channel_listeners[@channel][channel_name] = true end def remove_listener(channel_name, scope={}) if @@listeners[channel_name] @@listeners[channel_name].delete(@channel) if @@channel_listeners[@channel] @@channel_listeners[@channel].delete(channel_name) end end end # Called when a channel is closed, removes its listeners from # all channels. def close! channel_names = @@channel_listeners.delete(@channel) if channel_names channel_names.each_pair do |channel_name,val| remove_listener(channel_name) end end end def self.send_message_to_channel(channel_name, message, skip_channel=nil) listeners = @@listeners[channel_name] if listeners listeners.each do |listener| # We might need to skip a channel if the update came in on this # channel. next if listener == skip_channel listener.send_message(*message) end end end end
Version data entries
25 entries across 25 versions & 1 rubygems