client.go
func (c *Client) Idle(stop <-chan struct{}) error {
	if c.LogoutTimeout == 0 {
		return c.idle(stop)
	}

	t := time.NewTicker(c.LogoutTimeout)
	defer t.Stop()

	for {
		stopOrRestart := make(chan struct{})
		done := make(chan error, 1)
		go func() {
			done <- c.idle(stopOrRestart)
		}()

		select {
		case <-t.C:
			close(stopOrRestart)
			if err := <-done; err != nil {
				return err
			}
		case <-stop:
			close(stopOrRestart)
			return <-done
		case err := <-done:
			if err != nil {
				return err
			}
		}
	}
}
func (c *Client) Idle(stop <-chan struct{}) error {
	if c.LogoutTimeout == 0 {
		return c.idle(stop)
	}

	t := time.NewTicker(c.LogoutTimeout)
	defer t.Stop()

	for {
		stopOrRestart := make(chan struct{})
		done := make(chan error, 1)
		go func() {
			done <- c.idle(stopOrRestart)
		}()

		select {
		case <-t.C:
			close(stopOrRestart)
			if err := <-done; err != nil {
				return err
			}
		case <-stop:
			close(stopOrRestart)
			return <-done
		case err := <-done:
			if err != nil {
				return err
			}
		}
	}
}
// Idle indicates to the server that the client is ready to receive unsolicited
// mailbox update messages. When the client wants to send commands again, it
// must first close stop.