class Redis::SubscribedClient

def call(command, *args)

def call(command, *args)
  @client.call_async(command, *args)
end

def initialize(client)

def initialize(client)
  @client = client
end

def psubscribe(*channels, &block)

def psubscribe(*channels, &block)
  @client.call_async(:psubscribe, *channels)
  sub = Subscription.new(&block)
  begin
    loop do
      type, pattern, channel, message = @client.read
      sub.callbacks[type].call(pattern, channel, message)
      break if type == "punsubscribe" && channel == 0
    end
  ensure
    @client.call_async(:punsubscribe)
  end
end

def punsubscribe(*channels)

def punsubscribe(*channels)
  @client.call_async(:punsubscribe, *channels)
  @client
end

def subscribe(*channels, &block)

def subscribe(*channels, &block)
  @client.call_async(:subscribe, *channels)
  sub = Subscription.new(&block)
  begin
    loop do
      type, channel, message = @client.read
      sub.callbacks[type].call(channel, message)
      break if type == "unsubscribe" && message == 0
    end
  ensure
    @client.call_async(:unsubscribe)
  end
end

def unsubscribe(*channels)

def unsubscribe(*channels)
  @client.call_async(:unsubscribe, *channels)
  @client
end