func (c *Client) Disconnect() (err error) {
	c.RLock()
	if c.conn == nil {
		err = errors.New("no websocket connection exist")
		return
	}
	c.RUnlock()

	c.wsMutex.Lock()
	err = c.conn.WriteMessage(websocket.CloseMessage, websocket.FormatCloseMessage(websocket.CloseNormalClosure, ""))
	c.wsMutex.Unlock()
	if err != nil {
		logrus.Warningln(err)
	}
	select {
	case <-c.disconnected:
		// might get closed by another process
	case <-time.After(time.Second * 1):
		close(c.disconnected)
	}

	// give remainding processes some time to exit
	<-time.After(time.Second * 1)
	c.disconnected = nil

	// close connection
	err = c.conn.Close()
	c.conn = nil
	return
}
// Disconnect closes the discord websocket connection
Disconnect closes the discord websocket connection
// Disconnect closes the discord websocket connection
func (c *Client) Disconnect() (err error) {
	c.RLock()
	if c.conn == nil {
		err = errors.New("no websocket connection exist")
		return
	}
	c.RUnlock()
	c.wsMutex.Lock()
	err = c.conn.WriteMessage(websocket.CloseMessage, websocket.FormatCloseMessage(websocket.CloseNormalClosure, ""))
	c.wsMutex.Unlock()
	if err != nil {
		logrus.Warningln(err)
	}
	select {
	case <-c.disconnected:
	case <-time.After(time.Second * 1):
		close(c.disconnected)
	}
	<-time.After(time.Second * 1)
	c.disconnected = nil
	err = c.conn.Close()
	c.conn = nil
	return
}
func ( c * Client ) Disconnect ( ) ( err error ) { c . RLock ( ) if c . conn == nil { err = errors . New ( " " ) return } c . RUnlock ( ) c . wsMutex . Lock ( ) err = c . conn . WriteMessage ( websocket . CloseMessage , websocket . FormatCloseMessage ( websocket . CloseNormalClosure , " " ) ) c . wsMutex . Unlock ( ) if err != nil { logrus . Warningln ( err ) } select { case <- c . disconnected : case <- time . After ( time . Second * 1 ) : close ( c . disconnected ) } <- time . After ( time . Second * 1 ) c . disconnected = nil err = c . conn . Close ( ) c . conn = nil return }
Disconnect closes the discord websocket connection
Disconnect closes the discord websocket connection
// might get closed by another process // give remainding processes some time to exit // close connection