 
     .then (response) -> response.channels
 
-  # Unsubscribe from a channel.
-  unsubscribeAll: ->
-    @handlers = {}
-
-    new P (resolve, reject) =>
-      if @sock?
-        seq = @sequence
-        @sequence += 1
-        
-        record =
-          seq: seq
-          action: 'unsubscribe-all'
-        
-        @sock.send JSON.stringify(record)
-        .then =>
-          @outstanding.set seq,
-            resolve: resolve
-            reject: reject
-        .catch (error) ->
-          message = "Socket error while unsubscribing from channel:"
-          logger.error message, error
-          reject new errors.PubSubError message, error 
-        
-      else
-        message = "Could not unsubscribe from channel as the socket is currently disconnected."
-        logger.warn message
-        reject new errors.PubSubError message, null
-
-    .then (response) -> response.channels
-
   # List all channels to which this connection is subscribed.
   listSubscriptions: ->
     new P (resolve, reject) =>
       if @sock?
-        seq = @sequence
-        @sequence += 1
+        seq = @sequence += 1
         
         record =
           seq: seq

        reject new errors.PubSubError message, null

    .then (response) -> response.uuid
    
  # Publish a message to a channel.
  publish: (channel, message) ->
    new P (resolve, reject) =>
      if @sock?
        seq = @sequence
        @sequence += 1
        
        record =
          seq: seq
          action: 'pub'
          chan: channel
          msg: message
        
        @sock.send JSON.stringify(record)
        .then =>

            resolve: resolve
            reject: reject
        .catch (error) ->
          message = "Socket error while subscribing to channel:"
          logger.error message, error
          reject new errors.PubSubError message, error 
        
      else
        message = "Could not subscribe to channel as the socket is currently disconnected."
        logger.warn message
        reject new errors.PubSubError message, null

    .then (response) -> response.channels

    .catch (error) =>
      logger.error "Error subscribing to channel '#{channel}'", error
      delete @handlers[channel]
      throw error

  # Unsubscribe from a channel.
  unsubscribe: (channel) ->
    delete @handlers[channel]

    new P (resolve, reject) =>
      if @sock?
        seq = @sequence += 1
        
        record =
          seq: seq
          action: 'unsubscribe'
          channel: channel
        
        @sock.send JSON.stringify(record)
