client.go
func (c *Client) Stop() {
	// Tell reader and writer to end.
	close(c.doneChan)

	// We won't be sending anything further to writer. Let it clean up.
	close(c.sendChan)

	// Wait for reader and writer to end.
	c.wg.Wait()

	// We know the reader and writer won't be sending on the error channel any
	// more.
	close(c.errChan)

	_ = c.conn.Close()

	for range c.recvChan {
	}
	for range c.errChan {
	}
}
func (c *Client) Stop() {
	// Tell reader and writer to end.
	close(c.doneChan)

	// We won't be sending anything further to writer. Let it clean up.
	close(c.sendChan)

	// Wait for reader and writer to end.
	c.wg.Wait()

	// We know the reader and writer won't be sending on the error channel any
	// more.
	close(c.errChan)

	_ = c.conn.Close()

	for range c.recvChan {
	}
	for range c.errChan {
	}
}
// Stop shuts down the client and cleans up.
//
// You must not send any messages on the send channel after calling this
// function.