Skip to content

Instantly share code, notes, and snippets.

@DanKnox
Created October 27, 2013 21:44
Show Gist options
  • Save DanKnox/7188244 to your computer and use it in GitHub Desktop.
Save DanKnox/7188244 to your computer and use it in GitHub Desktop.
class ChannelManager
attr_reader :channels, :channel_tokens
def initialize
@channels = {}.with_indifferent_access
@channel_tokens = ChannelTokens.new
end
def [](channel)
@channels[channel] ||= Channel.new channel
end
def unsubscribe(connection)
@channels.each do |channel_name, channel|
channel.unsubscribe(connection)
end
end
class ChannelTokens
delegate :synchronize?, to: WebsocketRails
def initialize
@tokens = []
end
def include?(token)
if synchronize?
#check redis here
else
@tokens.include?(token)
end
end
def <<(token)
if synchronize?(token)
else
@tokens << token
end
end
def delete(token)
if synchronize?
# check redis here
else
@tokens.delete(token)
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment