func()

in conn.go [68:98]


func (client *Client) DialContext(ctx context.Context, network, address string) (*Conn, error) {
	if client.Dialer == nil {
		defaultDialer := &net.Dialer{}
		client.Dialer = defaultDialer.DialContext
	}

	conn, err := client.Dialer(ctx, network, address)
	if err != nil {
		return nil, fmt.Errorf("could not dial ZK server: %w", err)
	}

	sessionCtx, cancel := context.WithCancel(context.Background())
	c := &Conn{
		conn:           conn,
		sessionTimeout: defaultTimeout,
		cancelSession:  cancel,
		sessionCtx:     sessionCtx,
	}

	if client.SessionTimeout != 0 {
		c.sessionTimeout = client.SessionTimeout
	}
	if err = c.authenticate(); err != nil {
		return nil, fmt.Errorf("could not authenticate with ZK server: %w", err)
	}

	go c.handleReads()
	go c.keepAlive()

	return c, nil
}