code: func (c *Client) dequeuer() error {
  	for {
  		// acquire dequeue token
  		select {
  		case <-c.dequeueTokens:
  			// continue
  		case <-time.After(c.TokenTimeout):
  			return c.die(ClientError, ErrTokenTimeout)
  		case <-c.tomb.Dying():
  			return tomb.ErrDying
  		}
  
  		// request next message
  		msg, ack, err := c.backend.Dequeue(c)
  		if err != nil {
  			return c.die(BackendError, err)
  		} else if msg == nil {
  			return tomb.ErrDying
  		}
  
  		c.backend.Log(MessageDequeued, c, nil, msg, nil)
  
  		// prepare publish packet
  		publish := packet.NewPublish()
  		publish.Message = *msg
  
  		// set packet id
  		if publish.Message.QOS > 0 {
  			publish.ID = c.session.NextID()
  		}
  
  		// store packet if at least qos 1
  		if publish.Message.QOS > 0 {
  			err := c.session.SavePacket(session.Outgoing, publish)
  			if err != nil {
  				return c.die(SessionError, err)
  			}
  		}
  
  		// acknowledge message
  		if ack != nil {
  			ack()
  
  			c.backend.Log(MessageAcknowledged, c, nil, msg, nil)
  		}
  
  		// send packet
  		err = c.send(publish, true)
  		if err != nil {
  			return c.die(TransportError, err)
  		}
  
  		// immediately put back dequeue token for qos 0 messages
  		if publish.Message.QOS == 0 {
  			select {
  			case c.dequeueTokens <- struct{}{}:
  			default:
  				// continue if full for some reason
  			}
  		}
  
  		c.backend.Log(MessageForwarded, c, nil, msg, nil)
  	}
  }
docs: // message dequeuer