func ConnectServer(addr address.Address, updateCallback updateTopologyCallback, topologyID primitive.ObjectID, opts ...ServerOption) (*Server, error) {
	srvr, err := NewServer(addr, topologyID, opts...)
	if err != nil {
		return nil, err
	}
	err = srvr.Connect(updateCallback)
	if err != nil {
		return nil, err
	}
	return srvr, nil
}
ConnectServer creates a new Server and then initializes it using the
Connect method.
package topology
import (
	"context"
	"errors"
	"fmt"
	"net"
	"sync"
	"sync/atomic"
	"time"
	"go.mongodb.org/mongo-driver/bson/primitive"
	"go.mongodb.org/mongo-driver/event"
	"go.mongodb.org/mongo-driver/mongo/address"
	"go.mongodb.org/mongo-driver/mongo/description"
	"go.mongodb.org/mongo-driver/x/mongo/driver"
	"go.mongodb.org/mongo-driver/x/mongo/driver/operation"
)
const minHeartbeatInterval = 500 * time.Millisecond
var (
	ErrServerClosed = errors.New("server is closed")
	ErrServerConnected = errors.New("server is connected")
	errCheckCancelled = errors.New("server check cancelled")
	emptyDescription  = description.NewDefaultServer("")
)
type SelectedServer struct {
	*Server
	Kind description.TopologyKind
}
func (ss *SelectedServer) Description() description.SelectedServer {
	sdesc := ss.Server.Description()
	return description.SelectedServer{
		Server: sdesc,
		Kind:   ss.Kind,
	}
}
const (
	disconnected int32 = iota
	disconnecting
	connected
	connecting
	initialized
)
func connectionStateString(state int32) string {
	switch state {
	case 0:
		return "Disconnected"
	case 1:
		return "Disconnecting"
	case 2:
		return "Connected"
	case 3:
		return "Connecting"
	case 4:
		return "Initialized"
	}
	return ""
}
type Server struct {
	cfg             *serverConfig
	address         address.Address
	connectionstate int32
	pool *pool
	done          chan struct{}
	checkNow      chan struct{}
	disconnecting chan struct{}
	closewg       sync.WaitGroup
	desc                   atomic.Value  
	updateTopologyCallback atomic.Value
	topologyID             primitive.ObjectID
	subLock             sync.Mutex
	subscribers         map[uint64]chan description.Server
	currentSubscriberID uint64
	subscriptionsClosed bool
	heartbeatLock      sync.Mutex
	conn               *connection
	globalCtx          context.Context
	globalCtxCancel    context.CancelFunc
	heartbeatCtx       context.Context
	heartbeatCtxCancel context.CancelFunc
	processErrorLock sync.Mutex
	rttMonitor       *rttMonitor
}
type updateTopologyCallback func(description.Server) description.Server