// Disconnect will send a DisconnectPacket and close the connection. // // If a timeout is specified, the client will wait the specified amount of time // for all queued futures to complete or cancel. If no timeout is specified it // will not wait at all. func (c *Client) Disconnect(timeout ...time.Duration) error { c.mutex.Lock() defer c.mutex.Unlock() // check if connected if c.state.get() != clientConnected { return ErrClientNotConnected } // finish current packets if len(timeout) > 0 { c.futureStore.await(timeout[0]) } // set state c.state.set(clientDisconnecting) // send disconnect packet err := c.send(packet.NewDisconnectPacket(), false) return c.end(err, true) }
func disconnectPacket() *packet.DisconnectPacket { return packet.NewDisconnectPacket() }