module Cargosocket::StreamAdapters::EMChannelAdapter
Constants
- CHANNELS
- DISPATCHERS
Public Class Methods
dispatch(to)
click to toggle source
# File lib/cargosocket/stream_adapters/e_m_channel_adapter.rb, line 8 def self.dispatch(to) # DISPATCHERS << to end
push(*to, message)
click to toggle source
# File lib/cargosocket/stream_adapters/e_m_channel_adapter.rb, line 12 def self.push(*to, message) to.each do |channel| if channel.is_a?(Symbol) CHANNELS[channel].push(message) if CHANNELS.has_key?(channel) else # channel.push(message) end end end
subscribe(*to)
click to toggle source
# File lib/cargosocket/stream_adapters/e_m_channel_adapter.rb, line 22 def self.subscribe(*to) callback = Proc.new return to.reduce({}) do |acc, channel| CHANNELS[channel] ||= EM::Channel.new acc[channel] = CHANNELS[channel].subscribe(&callback.curry[channel]) next acc end end
unsubscribe(from) { |channel| ... }
click to toggle source
# File lib/cargosocket/stream_adapters/e_m_channel_adapter.rb, line 31 def self.unsubscribe(from) from.each do |channel, cid| yield(channel) CHANNELS[channel].unsubscribe(cid) if CHANNELS[channel].num_subscribers == DISPATCHERS.count CHANNELS.delete(channel) end end end