code: func (c *Client) setState(s uint8) error {
  	c.stateLock.Lock()
  	err := c.state.Goto(s)
  	c.stateLock.Unlock()
  
  	if err != nil {
  		return err
  	}
  
  	switch s {
  	case ConnectedState:
  		c.emit(ConnectedEvent, nil)
  	case DisconnectedState:
  		c.emit(DisconnectedEvent, nil)
  	case ClosingState:
  		c.emit(ClosingEvent, nil)
  	case ClosedState:
  		c.emit(ClosedEvent, nil)
  	}
  
  	return nil
  }
docs: // Sets the client state in a thread-safe manner.