class Redis::SubscribedClient

def call(command)

def call(command)
  @client.process([command])
end

def initialize(client)

def initialize(client)
  @client = client
end

def psubscribe(*channels, &block)

def psubscribe(*channels, &block)
  subscription("psubscribe", "punsubscribe", channels, block)
end

def psubscribe_with_timeout(timeout, *channels, &block)

def psubscribe_with_timeout(timeout, *channels, &block)
  subscription("psubscribe", "punsubscribe", channels, block, timeout)
end

def punsubscribe(*channels)

def punsubscribe(*channels)
  call([:punsubscribe, *channels])
end

def subscribe(*channels, &block)

def subscribe(*channels, &block)
  subscription("subscribe", "unsubscribe", channels, block)
end

def subscribe_with_timeout(timeout, *channels, &block)

def subscribe_with_timeout(timeout, *channels, &block)
  subscription("subscribe", "unsubscribe", channels, block, timeout)
end

def subscription(start, stop, channels, block, timeout = 0)

def subscription(start, stop, channels, block, timeout = 0)
  sub = Subscription.new(&block)
  unsubscribed = false
  @client.call_loop([start, *channels], timeout) do |line|
    type, *rest = line
    sub.callbacks[type].call(*rest)
    unsubscribed = type == stop && rest.last == 0
    break if unsubscribed
  end
  # No need to unsubscribe here. The real client closes the connection
  # whenever an exception is raised (see #ensure_connected).
end

def unsubscribe(*channels)

def unsubscribe(*channels)
  call([:unsubscribe, *channels])
end